在Nutch爬虫爬取新浪的时候 爬取率低,抽查了相关种子发现新浪搜索页面的帖子爬取率很低。遂展开分析–

搜索页面的网页内容特点

和专业的搜索引擎一样,新浪的搜索引擎搜索结果往往是众多网页的聚合,既是众多内容的聚合,也是多种形式的聚合。

这就意味着要解析索引到的这些网页,需要编写很多解析插件。幸运的是大多数类型的新浪网页,虽然网页所属的板块不同,然而网页的结构类似,采用了相同的网页模板,对于这些网页,需要修改nutch的过滤插件regex-urlfilter.txt使其支持url,并在自己写的解析插件中支持这种url。至于其他网站的网页,以及新浪采用不同模板的网页暂不考虑,爬取率保证在90%以上即可。我们需要用新浪的新闻搜索引擎 搜索一些手机的相关新闻 按相关度排序。以华为为例,搜索的链接为
http://search.sina.com.cn/?range=all&c=news&q=%BB%AA%CE%AA&from=top&col=&source=&country=&size=&time=&a=&sort=rel,附上网页链接(用casperjs获取到的实时链接)

下面是在验证爬取率时出现的两种情况:多爬和少爬。

多出来的链接

Huawei
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303562“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303562“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303561“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303563“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303564“,
“http://tech.sina.com.cn/t/2015-12-04/doc-ifxmisxu6250009.shtml“,
“http://tech.sina.com.cn/n/m/2015-12-04/doc-ifxmifzc0801858.shtml“,
“http://tech.sina.com.cn/mobile/n/n/2015-12-03/doc-ifxmifze7557039.shtml“,
“http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9897708.shtml“,
“http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9897702.shtml“,
“http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9897441.shtml“,
“http://tech.sina.com.cn/notebook/pad/2015-12-03/doc-ifxmcnkr7786923.shtml“,
“http://vic.sina.com.cn/news/27/2015/1203/64664.html“,
“http://finance.sina.com.cn/roll/20151204/051923928311.shtml“,
“http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9876368.shtml“,
“http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9856572.shtml“,
“http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9857492.shtml“,
“http://news.sina.com.cn/o/2015-12-03/doc-ifxmihae8911723.shtml“,
“http://finance.sina.com.cn/roll/20151203/162923924081.shtml“,
“http://finance.sina.com.cn/stock/t/20151203/160123923837.shtml“,
“http://news.sina.com.cn/o/2015-12-03/doc-ifxmihae8894721.shtml“,
“http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9840543.shtml“,
“http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9837605.shtml“,
“http://news.sina.com.cn/o/2015-12-03/doc-ifxmihae8890319.shtml”
共24条链接,其中第1-5行是第一个帖子的链接(幻灯片式网页),后面19行为2-20个帖子的链接。用nutch爬下来发现共19个链接,少爬的链接后面分析,这里多出一个链接:
http://news.sina.com.cn/c/2013-01-29/171826152112.shtml
这个链接不是网页上的,经测试此链接在换关键词为例搜索的时候也时常会出现,有时也会多出其他链接,然而并不影响爬取率,所以暂时不做处理。

少爬的链接

通过观察日志找到爬取的链接
http://news.sina.com.cn/o/2015-12-03/doc-ifxmihae8911723.shtml
http://finance.sina.com.cn/stock/t/20151204/105623933366.shtml
http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9857492.shtml
http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9840543.shtml
http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9856572.shtml
http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9897441.shtml
http://tech.sina.com.cn/t/2015-12-04/doc-ifxmisxu6250009.shtml
http://news.sina.com.cn/o/2015-12-03/doc-ifxmihae8894721.shtml
http://finance.sina.com.cn/stock/t/20151203/160123923837.shtml
http://finance.sina.com.cn/roll/20151203/162923924081.shtml
http://news.sina.com.cn/c/2013-01-29/171826152112.shtml
http://finance.sina.com.cn/roll/20151204/051923928311.shtml
http://tech.sina.com.cn/n/m/2015-12-04/doc-ifxmifzc0801858.shtml
http://tech.sina.com.cn/mobile/n/n/2015-12-03/doc-ifxmifze7557039.shtml
http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9897708.shtml
http://news.sina.com.cn/o/2015-12-03/doc-ifxmhqaa9837605.shtml
http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9897702.shtml
http://news.sina.com.cn/o/2015-12-04/doc-ifxmhqaa9876368.shtml
http://tech.sina.com.cn/notebook/pad/2015-12-03/doc-ifxmcnkr7786923.shtml
和之前的capserjs取到的url进行对比,可以发现有些链接并没有爬取到,如下:
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303562“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303562“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303561“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303563“,
“http://slide.tech.sina.com.cn/mobile/slide_5_22298_65513.html?img=1303564“,
“http://vic.sina.com.cn/news/27/2015/1203/64664.html”
观察他们的特点发现它们的后缀不是.shtml,与我们在插件中判断url是否需要爬取的策略一致。可见我们的解决方案是可行的。

更复杂的情况

这次我们用华为,中兴,小米 做关键词分别进行搜索,结果发现少的链接数多了,多爬的也多了。开始我比较了三个数据:
网页实际的链接 a ->Nutch获取到的链接数 b ->实际爬取的链接数 c
发现b>a>c ,找不到原因,b中莫名其妙的多出一些重复。
后来发现其实是出链获取过程中,会获取重复的链接,对a/b/c都增加了去重,比较b和c,a和c,a和b都合理了。其实这时发现和简单的情况一样,比较a和c即可。

经验证我们过滤掉的url数目d满足:a-b+1=d。

MARK一下写的python去重和比较脚本

before = []
after = []
total = []
total_no_repeat =[]
irregular = []def remove_same_item(before_file, after_file):try:f = open(before_file)for each_line in f:piece =each_line.split(' ')before.append(piece[-1])f.close()before_deduplicated = list(set(before))before.sort()print ("after deduplication, size of outlinks: "+str(before_deduplicated.__len__()))# for each_line in before:#     print each_linef = open(after_file)for each_line in f:piece =each_line.split(' ')after.append(piece[-1])f.close()after_deduplicated = list(set(after))after.sort()print ("actual size of links to crawl: "+str(after_deduplicated.__len__()))# for each_line in after:#     print each_linefor each_line in after_deduplicated:if before_deduplicated.__contains__(each_line):before_deduplicated.remove(each_line)print (before_deduplicated.__len__())for each_line in before_deduplicated:print each_lineexcept ValueError:passdef count_irregular(file_name):try:f = open (file_name)for each_line in f:total.append(each_line)if not str(each_line).__contains__(".shtml"):irregular.append(each_line)print "number of links on webpages: "+str(total.__len__())total_no_repeat = list(set(total))total_no_repeat.sort()print "number of links on webpages after dedupaliction: "+str(total_no_repeat.__len__())print "number of irregular links on webpages: "+str(irregular.__len__())except ValueError:passcount_irregular('original.txt')
remove_same_item('before.txt','after.txt')

爬取新浪搜索内容遇到的问题及解决相关推荐

  1. 爬取新浪新闻[内容笔记代码整理]

    学习视频:网易云 Python网络爬虫实战 环境:python3.5,requests,bs4,json,pandas,re,datetime 主要完成内容:爬取了新浪新闻-国内新闻版块的新闻信息,包 ...

  2. Python爬虫爬取新浪新闻内容

    首先感谢丘祐玮老师在网易云课堂的Python网络爬虫实战课程,接下来也都是根据课程内容而写.一来算是自己的学习笔记,二来分享给大家参考之用. 课程视频大概是在16年11月录制的,现在是18年2月.其中 ...

  3. 从入门到入土:Python爬虫学习|实例练手|爬取新浪新闻搜索指定内容|Xpath定位标签爬取|代码注释详解

    此博客仅用于记录个人学习进度,学识浅薄,若有错误观点欢迎评论区指出.欢迎各位前来交流.(部分材料来源网络,若有侵权,立即删除) 本人博客所有文章纯属学习之用,不涉及商业利益.不合适引用,自当删除! 若 ...

  4. 基于scrapy框架爬取新浪体育部分板块内容

    import scrapy from selenium import webdriver from sohuPro.items import SohuproItem class SohuSpider( ...

  5. Python3:爬取新浪、网易、今日头条、UC四大网站新闻标题及内容

    Python3:爬取新浪.网易.今日头条.UC四大网站新闻标题及内容 以爬取相应网站的社会新闻内容为例: 一.新浪: 新浪网的新闻比较好爬取,我是用BeautifulSoup直接解析的,它并没有使用J ...

  6. [Python爬虫]爬取新浪理财师股票问答

    本文将与大家分享如何爬取新浪理财师股票问答. 一.背景介绍 1)爬取顺序: 在这里,根据已有的股票id列表,按照顺序,依次爬取每只股票下面的股票问答. 股票id格式: lines = ['300592 ...

  7. python爬取新浪新闻

    最近公司项目比较少,楼主闲了好长时间了,作为一个刚毕业几个月的新人,心里很烦躁,只能自己找点新东西去学了.看到周围好多人都接触了爬虫,再加上楼主最近沉迷吴宣仪不可自拔,每天投票投票,投票的同时需要监控 ...

  8. python爬虫-使用BeautifulSoup爬取新浪新闻标题

    ** python爬虫-使用BeautifulSoup爬取新浪新闻标题 ** 最近在学习爬虫的技巧,首先学习的是较为简单的BeautifulSoup,应用于新浪新闻上. import requests ...

  9. python-基于selenium库爬取微博关键词搜索内容

    python-基于selenium爬取微博关键词搜索内容 用的是谷歌浏览器 需要下载chromedriver 暂时还少了登录步骤不能爬取第一页以外的内容 爬取内容(默认了40条(还没有做到翻页所以会重 ...

最新文章

  1. GDAL中GDALDataset::RasterIO分块读取的实现
  2. 当你「ping 一下」的时候,你知道它背后的逻辑吗?
  3. python 将数组转化8位整数_int对象,永不溢出的整数
  4. 【英语学习】【Level 07】U04 Rest and Relaxation L4 A room fit for a king
  5. 剑指offer——替换字符串
  6. html用排序列表的方式添加,jQuery html表格排序插件tablesorter使用方法详解
  7. 3-unit8 Mariadb数据库
  8. matplotlib的一些代码
  9. 三维点云配准方法(两帧)
  10. 1041: 谭浩强C语言(第三版)习题5.5
  11. 科大讯飞语音合成实例
  12. python办公自动化pdf下载_最全总结 | 聊聊 Python 办公自动化之 PDF(上)
  13. C语言实战--解二元一次方程
  14. 3D检测入门知识梳理
  15. 2013校园招聘阶段小结
  16. 产品数据管理(PDM)技术说明书
  17. 棋盘(Checkerboard)算法
  18. 在线沙盒(恶意软件行为分析工具)整理介绍
  19. FaceShifter:新的人脸交换模型
  20. 专升本C语言试题分析(四)

热门文章

  1. 说一说埃隆.马斯克他妈妈的故事
  2. word文档保存修订信息,打开时默认不显示标记信息
  3. 剑灵系统推荐加点_剑灵新版力士加点解析及推荐键位设置
  4. 360私有化预计8月中旬完成:换汇时间表曝光
  5. ZYNQ初体验千兆以太网的那些事儿(ps端)
  6. win8 系统 激活
  7. Jquery 循环遍历table获取tr内指定的元素,并校验查重,删除元素值有相同的tr
  8. python的set函数用法——获取不重复的集合
  9. vue3使用vue-count-to组件
  10. js 返回上一页的操作