为了账号安全,请及时绑定邮箱和手机立即绑定

python爬虫对搜狗抓取微信搜索信息不全问题

python爬虫对搜狗抓取微信搜索信息不全问题

陪伴而非守候 2018-07-16 15:12:22
刚开始学习python爬虫,想实现对搜狗公众号搜索结果的爬取发现问题是抓到的信息没有直接在浏览器访问的URL信息完整。以下是基本实现,代码很简单,爬取到的页面中没有“最近文章”(在浏览器中直接访问有“最近文章”内容)请高手们指点一二,谢谢!#-*- coding: utf-8 -*-import urllib2import sysimport urllibfrom bs4 import BeautifulSoup reload(sys) sys.setdefaultencoding('utf8') url = 'http://weixin.sogou.com/gzh?openid=oIWsFt5l9RDYeAjdXZBYtGzbH0JI'print url i_headers = {"User-Agent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:32.0) Gecko/20100101 Firefox/32.0"} req = urllib2.Request(url, headers=i_headers) content = urllib2.urlopen(req).read() soup = BeautifulSoup(content)print soup siteUrls = soup.findAll(attrs={'class':'img_box2'})print siteUrls file_object = open('test.htm','w+') file_object.write(content) file_object.close()
查看完整描述

2 回答

?
慕桂英3389331

TA贡献2036条经验 获得超8个赞

谢谢,这个太有用了,得到这个列表后,我估计就得做个截取页面,把数据实时显示,不知道能不能ok,不过,就是不知道这个方式,以后会不会关闭掉。

查看完整回答
反对 回复 2018-07-17
  • 2 回答
  • 0 关注
  • 363 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信