Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python请求错误10060_Python_Web Crawler_Python Requests_Urllib - Fatal编程技术网

Python请求错误10060

Python请求错误10060,python,web-crawler,python-requests,urllib,Python,Web Crawler,Python Requests,Urllib,我有一个脚本可以在网站上爬行。 直到今天它运行得很完美, 然而,它现在没有这样做 它会给sme带来以下错误: Connection Aborted Error(10060 ' A connection attempt failed becvause the connected party did not properly respond after a period of time, or established a connection failed because connected ho

我有一个脚本可以在网站上爬行。 直到今天它运行得很完美, 然而,它现在没有这样做

它会给sme带来以下错误:

 Connection Aborted Error(10060 ' A connection attempt failed becvause the connected party did not properly respond after a period of time, or established a connection failed because connected host has failed to respond'
我一直在寻找答案和设置,但我不知道如何解决这个问题

在IE中,我不使用任何代理(连接->局域网设置->代理=禁用)

它打断了这段代码,有时是第一次运行,有时是第二次运行。。等等

def geturls(functionurl, runtime):
startCrawl = requests.get(functionurl, headers=headers)
mainHtml = BeautifulSoup(startCrawl.content, 'html.parser')
mainItems = mainHtml.find("div",{"id": "js_multiselect_results"})
for tag in mainItems.findAll('a', href=True):
    tag['href'] = urlparse.urljoin(url,tag['href'])
    if shorturl in tag['href'] and tag['href'] not in visited:
        if any(x in tag['href'] for x in keepout):
            falseurls.append(tag['href'])
        elif tag['href'] in urls:
            doubleurls.append(tag['href'])
        else:
            urlfile.write(tag['href'] + "\n")
            urls.append(tag['href'])

totalItemsStart = str(mainHtml.find("span",{"id": "sab_header_results_size"}))
if runtime == 1:
    totalnumberofitems[0] = totalItemsStart
    totalnumberofitems[0] = strip_tags(totalnumberofitems[0])
return totalnumberofitems

如何解决此问题?

尝试增加
请求的
超时
参数。获取
方法:

requests.get(functionurl, headers=headers, timeout=5)
但是,您的脚本很有可能被服务器阻止,以防止放弃尝试。如果是这种情况,您可以通过设置适当的标题来尝试伪造web浏览器

{"User-Agent": "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.8) Gecko/20100722 Firefox/3.6.8 GTB7.1 (.NET CLR 3.5.30729)", "Referer": "http://example.com"}

你的脚本可能被阻止了,因为很明显你是一个扫描器。这是怎么明显的?我每5秒请求一页。我用标题让网站认为我是一个用户。对不起,我并不是故意粗鲁。但是,您的所有请求都来自一个IP地址,每5秒一次。如果有人在看服务器日志或运行原始的监控软件,你会作为一个离群者和一个抓取机器人脱颖而出。我不认为这是粗鲁的,只是想得到一个解释。然而,我确实需要一个修复这个!我在网站提供的页面请求数量的限制内(每小时1800次)。我唯一没有做的事情就是服从他们的机器人。TXT找到另一种方法来进行循环IPs的刮取,你也可以尝试使用scrapy,它有一些内置的技巧来掩饰你正在做的事情。我没有timeout参数,但我有headers(因此headers=headers)。我没有的是.net和referer参数。referer是做什么的?