sinat_32635107 2017-10-22 15:00 采纳率: 60%
浏览 4152
已采纳

python 爬虫XHR获取失败

需求是这样的,我需要写一个爬虫把
http://www.bjbus.com/home/fun_news_list.php?uNewsType=1&uStyle=1
上的所有list和其中的链接爬下来并每天定时查看有没有新的公告。进行简单的
response = urllib2.urlopen('http://www.bjbus.com/home/fun_news_detail.php?uNewsCode=00003475&uNewsType=1')
print html = response.read()
发现没有我想要的内容,进一步我发现我想要的东西是通过这个发来的
http://www.bjbus.com/home/ajax_news_list.php
但我单独请求这个没有任何返回,尝试了自己编写headers后无果,请大神们帮帮忙
怎么才能获得所有的公告和其对应的链接。

  • 写回答

2条回答 默认 最新

  • karen__ 2017-10-23 04:09
    关注

    你要用post去请求,我使用的是request库
    import requests
    url = 'http://www.bjbus.com/home/ajax_news_list.php'
    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
    data = {'txtPage':1, 'txtDisplayRows':9, 'txtType':1, 'txtCode':'', 'txtContainer':'content', 'txtStyle':1}
    response = requests.post(url, headers = headers, data = data)
    print(response.content.decode('utf-8'))

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏
  • ¥30 backtrader对于期货交易的现金和资产计算的问题
  • ¥15 求C# .net4.8小报表工具
  • ¥15 安装虚拟机时出现问题
  • ¥15 Selenium+docker Chrome不能运行
  • ¥15 mac电脑,安装charles后无法正常抓包
  • ¥18 visio打开文件一直显示文件未找到