- 论坛徽章:
- 0
|
Normal
0
7.8 磅
0
2
false
false
false
EN-US
ZH-CN
X-NONE
MicrosoftInternetExplorer4
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.5pt;
mso-bidi-font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:宋体;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:"Times New Roman";
mso-bidi-theme-font:minor-bidi;
mso-font-kerning:1.0pt;}
利用python检查搜索引擎的准确率
File information
2009-11-10
磁针石:xurongzhong#gmail.com
博客:
oychw.cublog.cn
腾讯搜搜的主页为:
http://www.soso.com/
,比如输入“武冈”,则会返回包含如下信息的网页:a href="http://www.wugang.gov.cn/" id="res0" 这表示
www.wugang.gov.cn
为搜索结果的第一条记录(res0,记录从0开始计数)。这样就方便使用正则表达式来抓取。 把要搜索的关键字和网址存入c:\word.txt,样式如下:武冈 www.wugang.gov.cn武冈
www.wugangren.com
输出结果存放于c:\out.csv。代码如下: import urllib2import re f = open("c:\out.csv",'w')for line in open("c:\word.txt"): word,address= line.split() print "\n--------" + word,address, url = "http://www.soso.com/q?pid=s.idx&w=" + word response = urllib2.urlopen(url) html = response.read() if address in html: text = address+'.*?res([0-9]*)' m = re.search(text, html, re.IGNORECASE) result = m.group(1) print "-----------ok", else: result = "Not found!" print "-----------!!!!!!!!----- fail", f.write(word+","+address+","+result+"\n")f.close() 如果数据量比较大的话,需要采用多线程或者进程。不过实际执行中,腾讯对单个IP不允许过多的搜索量,还需要研究IP伪造。 相关文件:
![]()
文件:新建文件夹.rar
大小:4KB
下载:
下载
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21908/showart_2090370.html |
|