[问题]百度上使用 site inurl

sh/bash/dash/ksh/zsh等Shell脚本
回复
cublog
帖子: 4
注册时间: 2008-08-29 9:42

[问题]百度上使用 site inurl

#1

帖子 cublog » 2008-08-29 11:13

你尝试过在百度上使用 site inurl 语法查询吗 ? 如果还没有的话可以试一下 :)

如输入 site:www.baidu.com inurl:news

则会搜出所有在 www.baidu.com 站点上的包含 "news" 子串的 url 。

现在我们有两份数据,一份是 site_inurl.txt 一份是 url.txt

site_inurl.txt 中每行是一个 site inurl 语法组成的查询串, url.txt 中保存的是 url 列表。

你能否在 url 列表中找出所有能被 site_inurl.txt 中的查询串检索到的 url?

如 site_inurl.txt 内容如下:

site:www.baidu.com inurl:/more

site:zhidao.baidu.com inurl:/browse/

site:www.sina.com.cn inurl:www20041223am

url.txt 内容如下:

http://www.baidu.com/more/

http://www.baidu.com/guding/more.html

http://www.baidu.com/events/20060105/photomore.html

http://hi.baidu.com/browse/

http://hi.baidu.com/baidu/

http://www.sina.com.cn/head/www20021123am.shtml

http://www.sina.com.cn/head/www20041223am.shtml

则你的程序运行完输出的结果应该为:

http://www.baidu.com/more/

http://www.baidu.com/guding/more.html

http://www.sina.com.cn/head/www20041223am.shtml

程序以命令行形式传入这两个文件名,第一个参数为 site_inurl 文件对应的文件名,第二个参数为 url 列表对应的文件名,程序的输出请输出到标准输出

shell实现~~~~help
cublog
帖子: 4
注册时间: 2008-08-29 9:42

#2

帖子 cublog » 2008-08-30 14:28

我目前的想法是:
#!/bin/bash
while read line
do
set p1='echo $line | awk -F"[: ]" '{print $2}''
set p2='echo $line | awk -F"[: ]" '{print $4}''
echo $p1,$p2
grep "$p1.*$p2" url.txt
unset p1;
unset p2;

done < inurl.txt
貌似shell把'echo $line | awk -F"[: ]" '和结尾的''结合到一块去鸟,不解~~~
cublog
帖子: 4
注册时间: 2008-08-29 9:42

#3

帖子 cublog » 2008-08-31 18:45

问题解决了,原来是变量没弄好,自己无意中发现的
while read -r line
do set $(echo $line | awk -F"[: ]" '{print $2,$4}')
grep "$1.*$2" url.txt
done<inurl.txt
头像
keky
帖子: 231
注册时间: 2007-12-20 15:08
来自: harbin
联系:

Re: [问题]百度上使用 site inurl

#4

帖子 keky » 2008-09-22 8:15

1 #!/bin/bash
2 while read site inurl
3 do
4 site=$( echo $site | sed 's/\w*://g' )
5 inurl=$( echo $inurl | sed 's/\w*://g' )
6 # echo "site=$site inurl=$inurl"
7 cat $2 | grep "^http://$site" | grep "$inurl"
8 done < $1
这样不知道是不是符合题意
回复