Sto cercando di usare Python per accedere a un sito web e raccogliere informazioni da diverse pagine web e ottengo il seguente errore:Come evitare l'errore HTTP 429 (troppe richieste) pitone
Traceback (most recent call last): File "extract_test.py", line 43, in <module> response=br.open(v) File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 203, in open return self._mech_open(url, data, timeout=timeout) File "/usr/local/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 255, in _mech_open raise response mechanize._response.httperror_seek_wrapper: HTTP Error 429: Unknown Response Code
ho usato time.sleep()
e funziona, ma sembra non intelligente e inaffidabile, c'è qualche altro modo per evitare questo errore?
Ecco il mio codice:
import mechanize
import cookielib
import re
first=("example.com/page1")
second=("example.com/page2")
third=("example.com/page3")
fourth=("example.com/page4")
## I have seven URL's I want to open
urls_list=[first,second,third,fourth]
br = mechanize.Browser()
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Browser options
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
# Log in credentials
br.open("example.com")
br.select_form(nr=0)
br["username"] = "username"
br["password"] = "password"
br.submit()
for url in urls_list:
br.open(url)
print re.findall("Some String")
Non c'è niente da fare, questo è un applicazione sul server- lato tenendo traccia di quante richieste/unità di tempo effettuate. Se superi questa unità, sarai temporaneamente bloccato. Alcuni server inviano queste informazioni nell'intestazione, ma quelle occasioni sono rare. Controlla le intestazioni ricevute dal server, usa le informazioni disponibili .. In caso contrario, controlla quanto velocemente puoi martellare senza essere scoperti e usa un "sonno". – Torxed
http://stackoverflow.com/questions/15648272/how-do-you-view-the-request-headers-that-mechanize-is-using – Torxed