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

为什么有些网站能显示内容但python.requests却爬不出数据呢?

为什么有些网站能显示内容但python.requests却爬不出数据呢?

慕田峪7331174 2018-09-04 13:18:19
打算在http://app1.sfda.gov.cn/上获取一些数据整理起来,想用python.requests实现一个小爬虫来获取数据,但是python.requests会一直报('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')的错误,但是那个网站是的的确确能上的,各位有知道我错在哪里吗,谢谢??代码如下:import requestsdef testLoadRequest():    officialHeader = {        'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) '                     'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36',        'referer':'http://app1.sfda.gov.cn/',        'Upgrade-Insecure-Requests':'1'    }    officialUrl = 'http://app1.sfda.gov.cn';    try:        officialRequest = requests.get(officialUrl, headers= officialHeader)        print(officialRequest.content)    except Exception as e:        print(e)testLoadRequest()
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 3107 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号