Linux · 2009-04-28

shell批量获取百度及google收录与alexa排名

这个shell脚本查询百度收录及alexa排名没有包含google,google要多增加一个cook跟referer的资料,不然得不到页面..修改一下域名跟路径就可以用了~

#!/bin/bash
cd /root/get_google_baidu_site
$(curl http://alexa.chinaz.com/?domain=baiqiuyi.com -o alexa.temp && cat alexa.temp |iconv -f gb2312 -t utf8|grep 综合排名|sed -e 's/<[^>]*>//g' -e 's/^[ \t]*//g' -e '2d' > today.result && rm alexa.temp)
$(wget -q http://www.baidu.com/s?wd=site%3Abaiqiuyi.com -O baiqiuyi.temp)
$(head -80 baiqiuyi.temp|iconv -f gb2312 -t utf8 > baiqiuyi.html && rm baiqiuyi.temp)
curl -A "Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.0)" -e "www.google.cn" -D google.txt "http://www.google.cn/search?hl=zh-CN&q=site%3Abaiqiuyi.com&btnG=Google+%E6%90%9C%E7%B4%A2&meta=&aq=f&oq="|sed -e 's/<[^>]*>//g' -re 's/.*(中国的网页  网页 .*项符合 baiqiuyi\.com).*/\1/g;'|grep "中国的网页  网页 约有"|sed -e 's/ //g' -e 's/中国的网页 网页/baiqiuyi.com Google 一下/' -e 's/ baiqiuyi\.com//g' >> today.result
   $(sed -e '/百度一下/!d' -e 's/<[^>]*>//g' -e 's/ //g' -e '1,2d' baiqiuyi.html >> today.result|echo -e "\n\n" >>today.result && rm baiqiuyi.html)
$(cat kof1.temp|iconv -f gb2312 -t utf8 > kof1.result && rm kof1.temp)
$(sed -e '/百度一下/!d' -e 's/<[^>]*>//g' -e 's/ //g' -e '1,2d' kof1.result >> today.result |echo -e "\n\n"$(date) >> today.result && rm kof1.result)
clear
cat /root/get_google_baidu_site/today.result && rm /root/get_google_baidu_site/today.result

得到的结果大概为这样:

网站 www.baiqiuyi.com 在 Alexa 上综合排名第 210,313 位。
baiqiuyi.com Google 一下约有 246 项符合
百度一下,找到相关网页197篇,用时0.001秒

Tue Apr 28 21:43:05 CST 2009