Submitting Forms with Mechanize (Python)

自闭症网瘾萝莉.ら 提交于 2019-11-28 10:11:58
tovmeod

to select a form using its name you should use:

br.select_form(name="order")

what you are doing here:

br.form["username"] = 'usernamehere'

is trying to set a value to a control under the selected form, so when he can't find it, it throws the exception you are seeing.

You might have several issues

  • if the form is generated through javascript, you can't solve it with mechanize - at least not in a straight forward way - in this case I recommend you to try and use selenium - you can try to look at the page HTML source - if you don't have the form there in pure html, it is pretty clear that it is inserted into DOM by javascript. Also, if the form is submitted through javascript, mechanize won't help you

  • also, the form might not be on the first page - you might want to set mechanize to follow the redirects

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