Following the result of pressing a submit button in Python Mechanize

隐身守侯 提交于 2019-12-10 23:59:42

问题


So I have an authenticated site that I want to access via the mechanize module. I'm able to log in, and then go to the page I want. However, because the page recognizes that mechanize doesn't have javascript enabled, it wants me to click a submit button to get redirected to a non javascript part of the site. How can I simply click the button and then read the contents of the page that follows that?

Or, is there a way to trick it into thinking that my javascript is enables?

Thanks!


回答1:


if that submit button is really a submit input element of the form, and the redirection works as usual form submit action, and provided that it's the only form in the page, your mechanize browser instance is br, following should work

br.select_form(nr=0) # select the first form
br.submit()

afaik, there's no simple or moderately possible way, how to emulate javascript in mechanize, possible workarounds depend on what is javascript exactly doing



来源:https://stackoverflow.com/questions/3901218/following-the-result-of-pressing-a-submit-button-in-python-mechanize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!