pythonmechanicalsoup

mechanicalsoup TypeError: 'module' object is not callable


I've read the previous posts here on the subject problem, although not specifically for mechanicalsoup, which mostly indicated a possible conflict between the module and class name, but I don't see how that would apply here.

I created a .py text file with two lines: Also tried from mechanicalsoup import mechanicalsoup which resulted in an error. In case it is helpful, this is the output from print(mechanicalsoup): module mechanicalsoup from

'C:\Users\peterk\AppData\Local\Programs\Python\Python37-32\lib\site-packages\mechanicalsoup\__init__.py'

import mechanicalsoup
browser=mechanicalsoup.stateful_browser()

When run, the output is:

C:\Temp>bf.py

Traceback (most recent call last):

File "C:\Temp\bf.py", line 2, in

browser=mechanicalsoup.stateful_browser()

TypeError: 'module' object is not callable


Solution

  • Let me try to help you out. Firstly install latest mechanicalsoup by following this LINK

    Then try this.

    import mechanicalsoup
    
    browser=mechanicalsoup.StatefulBrowser()
    browser.open("http://httpbin.org/")
    

    And if you want to use stateful_browser use it like

    browser=mechanicalsoup.stateful_browser
    

    But it has no attribute open which is actually your aim. That is why use the StatefulBrowser as mentioned in their documentation