Mechanize for Python 3.x

喜你入骨 提交于 2019-11-29 08:38:59

问题


is there any way how to use Mechanize with Python 3.x?

Or is there any substitute which works in Python 3.x?

I've been searching for hours, but I didn't find anything :(

I'm looking for way how to login to the site with Python, but the site uses javascript.

Thanks in advance,

Adam.


回答1:


lxml.html provides form handling facilities and supports Python 3.




回答2:


I'm working on a similar project, but the faq for mechanize explicitly says they don't intend on supporting 3x any time soon. Is there a reason the code has to be written in 3?

The way I'm trying to tackle the problem is by emulating the java script with form submits, it takes some reverse engineering. (which is, if the javascript ends by submitting a form, and you can find the arguments the script passes to the submit(), just follow the example from the mechanize doc

http://wwwsearch.sourceforge.net/mechanize/

br.select_form(name="order")
# Browser passes through unknown attributes (including methods)
# to the selected HTMLForm.
br["cheeses"] = ["mozzarella", "caerphilly"]  # (the method here is __setitem__)
# Submit current form.  Browser calls .close() on the current response on
# navigation, so this closes response1
response2 = br.submit()


来源:https://stackoverflow.com/questions/4237164/mechanize-for-python-3-x

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