免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3272 | 回复: 0
打印 上一主题 下一主题

利用python检查搜索引擎的准确率 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-11-10 07:54 |只看该作者 |倒序浏览


  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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP