2015-01-03 10 views
1

웹 사이트를 크롤링하는 스크립트가 있습니다. 오늘까지 완벽하게 달렸습니다 그러나 지금은 그렇게하지 않습니다.Python이 오류 10060을 요청합니다.

는 중소 다음과 같은 오류 제공 :

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' 

내가 답변의 ANS 설정으로 찾고있다을하지만 난이 문제를 해결하는 방법을 알아낼 수 없습니다 ...

가 IE에서 내가 어떤 프록시를 사용하고 있지 않다 (연결 -> LAN 설정 -> 프록시 = 사용 안 함)

는,이 코드 조각 나누기 첫 번째 실행을 somethimes는 .. 등등에서 2 위를 somethimes

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 방법의 timeout 매개 변수를 증가

+1

스 크레이 퍼인 것이 분명하기 때문에 스크립트가 차단 된 것 같습니다. –

+0

어떻게 알 수 있습니까? 5 초마다 한 번씩 페이지를 요청합니다. 그리고 나는 웹 사이트를 내가 사용자라고 생각하게하기 위해 헤더를 사용합니다. – brian

+0

나는 무례하게하려고하지 않았습니다. 미안합니다. 그러나 모든 요청은 5 초마다 하나의 IP 주소에서 이루어집니다. 누군가가 서버 로그를 보거나 원시 모니터링 소프트웨어를 실행하고 있다면, 당신은 분명히 이상 치와 긁어 모으는 봇으로 눈에. 것입니다. –

답변

1

시도 :

requests.get(functionurl, headers=headers, timeout=5) 

그러나 확률이 스크립트가 폐기 시도를 방지하기 위해 서버에 의해 차단되고 있음이다. 이 경우 적절한 헤더를 설정하여 웹 브라우저를 위조 해 볼 수 있습니다.

{"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"} 
+0

timeout 매개 변수가 없지만 헤더가 있습니다 (따라서 헤더 = 헤더). 내가 가지고 있지 않은 것은 .net 및 referer 매개 변수입니다. 리퍼러는 무엇을합니까? – brian

관련 문제