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

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -