BeautifulSoup(html) not working, saying can't call module?

后端 未结 3 1388
无人共我
无人共我 2021-01-17 17:27
import urllib2
import urllib
from BeautifulSoup import BeautifulSoup        # html
from BeautifulSoup import BeautifulStoneSoup     # xml
import BeautifulSoup                


        
相关标签:
3条回答
  • 2021-01-17 17:48

    @Blair's answer has the right slant but I'd perform some things slightly differently, i.e.:

    import BeautifulSoup
    Soup = BeautifulSoup.BeautifulSoup
    

    (recommended), or

    import BeautifulSoup
    from BeautifulSoup import BeautifulSoup as Soup
    

    (not bad either).

    0 讨论(0)
  • 2021-01-17 17:49

    Your import BeautifulSoup makes BeautifulSoup refer to the module, not the class as it did after from BeautifulSoup import BeautifulSoup. If you're going to import the whole module, you might want to omit the from ... line or perhaps rename the class afterward:

    from BeautifulSoup import BeautifulSoup 
    Soup = BeautifulSoup
    ...
    import BeautifulSoup
    ....
    soup = Soup(html)
    
    0 讨论(0)
  • 2021-01-17 18:00

    Install BeautifulSoup4
    sudo easy_install BeautifulSoup4

    Recommendation
    from bs4 import BeautifulSoup

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