I get an error in python3 when importing mechanize

前端 未结 3 1376
感情败类
感情败类 2020-12-17 09:52

I get an error in python3 when importing mechanize.

I\'ve just installed mechanize into my virtualenv where python3 is installed.

$ which python3
/Us         


        
相关标签:
3条回答
  • 2020-12-17 10:29

    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
    
    0 讨论(0)
  • 2020-12-17 10:37

    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.

    0 讨论(0)
  • 2020-12-17 10:46

    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

    0 讨论(0)
提交回复
热议问题