I get an error in python3 when importing mechanize

[亡魂溺海] 提交于 2019-11-29 05:33:49

Alas, mechanize doesn't support Python 3. http://wwwsearch.sourceforge.net/mechanize/faq.html

Python 2.4, 2.5, 2.6, or 2.7. Python 3 is not yet supported.

You might like to comment on the issue at https://github.com/jjlee/mechanize/issues/96


Update: I wrote my own automating library MechanicalSoup. It's Python 3 compatible https://github.com/hickford/MechanicalSoup

The module MechanicalSoup merged Mechanical and BeautifulSoup in the same Library and can be used since Python 2.6 through 3.4.

in command prompt install MechanicalSoup:

pip install MechanicalSoup

Then import in python,

import mechanicalsoup # Don’t forget to import the new module

I think you may have installed the Python 2 version of mechanize, and the new Python 3 import semantics are breaking the old Python 2 code. A quick search, and it seems like Python 3 support for mechanize is still a bit weak. However, I did find a Python 3 branch.

You could try manually installing from the source code I linked to. Once you've downloaded the source, change your directory so that you're in the mechanize directory. Then enter $python3 setup.py install in the terminal.

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