On 30 August 2012 19:03, Tom <
boo...@gmail.com> wrote:
> have any suggestions for catching these, passing them by, and continuing on
> with the loop?
>
>
> for link in row.find_all('a', limit=1):
> y = (link.get('href'))
> time.sleep(15)
> try:
> data = urllib2.urlopen(y).read()
> except HTTPError, e:
> print "The server could not fulfill the request."
> print "Error code: ", e.code
> time.sleep(100)
> except URLError, e:
> print "We failed to reach a server."
> print "Reason: ", e.reason
> soup1 = BeautifulSoup(data, "html5lib",
> from_encoding="utf-8")
Two suggestions:
* use a continue in the except clauses, which probably isn't necessary if
* you move "soup1 = BeautifulSoup(data, "html5lib",
from_encoding="utf-8")" inside the try. As it stands, it's calling
BeautifulSoup with an empty object. It may even say that in the
backtrace if you check it. :-)
--
Paul