Search code examples
pythonmechanizemechanize-python

Python mechanize wait and click


Using mechanize, how can I wait for some time after page load (some websites have a timer before links appear, like in download pages), and after the links have been loaded, click on a specific link? Since it's an anchor tag and not a submit button, will browser.submit() work(I got errors while doing that)?


Solution

  • Mechanize does not offer javascript functionality, so you will not see dynamic content (like a timer that turns into a link).

    As far as clicking on a link, you have to find the element, and then you can call click_link on it. See the Finding Links section of this site.

    If you are looking for something to handle such sites, a good option is PhantomJS. It uses nodejs, but runs on the webkit engine, allowing you parse dynamic content. If you have your heart set on python, using Selenium to programatically drive a real browser may be your best bet.