Python mechanize is not handling form exception -
i writing web scraper using python , mechanize. scraper looks "next" button , loops until comes last page, not have "next" button. gives formnotfounderror: exception, stops loop. when try catch exception, nameerror: instead of actual error. doing wrong? alternatively, there better way stop loop when have reached end?
here relevant code.
import mechanize br = mechanize.browser() br.open("http://example.com") x=0 while x > 1: try: br.select_form(nr=2) response = br.submit("next") *otherstuff* except formnotfounderror: break here error output.
file "scraping.py", line 32, in <module> except formnotfounderror: nameerror: name 'formnotfounderror' not defined
can try change to:
except mechanize._mechanize.formnotfounderror: instead of this:
except formnotfounderror:
Comments
Post a Comment