How to click a link that has [removed]__doPostBack in href?

前端 未结 3 1474
眼角桃花
眼角桃花 2020-12-05 12:40

I am writing a screen scraper script in python with module \'mechanize\' and I would like to use the mechanize.click_link() method on a link that has javascript:__doPostBack

3条回答
  •  情深已故
    2020-12-05 12:55

    I don't use mechanize, but I do a lot of web scraping myself with python.

    When I run into a javascript function like __doPostBack, I do the following:
    I access the web site in Firefox, and use the HttpFox extension to see the parameters of the POST request the browser sent to the web server when clicking the relevant link.
    I then build the same request in python using urllib.parse.urlencode to build the query strings and POST data I need.
    Sometimes the website uses cookies as well, so I just use python's http.cookiejar.

    I have used this technique successfully several times.

提交回复
热议问题