猿问

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

打算在http://app1.sfda.gov.cn/上获取一些数据整理起来,想用python.requests实现一个小爬虫来获取数据,但是python.requests会一直报('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')的错误,但是那个网站是的的确确能上的,各位有知道我错在哪里吗,谢谢??

代码如下:

import requests

def 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()


慕田峪7331174
浏览 3108回答 1
1回答
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答