ImportError: No module named BeautifulSoup

前端 未结 8 1148
無奈伤痛
無奈伤痛 2020-11-28 23:50

I have installed BeautifulSoup using easy_install and trying to run following script

from BeautifulSoup import BeautifulSoup
import re

doc = [\'         


        
相关标签:
8条回答
  • 2020-11-29 00:44

    On Ubuntu 14.04 I installed it from apt-get and it worked fine:

    sudo apt-get install python-beautifulsoup

    Then just do:

    from BeautifulSoup import BeautifulSoup

    0 讨论(0)
  • 2020-11-29 00:47

    you can import bs4 instead of BeautifulSoup. Since bs4 is a built-in module, no additional installation is required.

    from bs4 import BeautifulSoup
    import re
    
    doc = ['<html><head><title>Page title</title></head>',
           '<body><p id="firstpara" align="center">This is paragraph <b>one</b>.',
           '<p id="secondpara" align="blah">This is paragraph <b>two</b>.',
           '</html>']
    soup = BeautifulSoup(''.join(doc))
    
    print soup.prettify()
    

    If you want to request, using requests module. request is using urllib, requests modules. but I personally recommendation using requests module instead of urllib

    module install for using:

    $ pip install requests
    

    Here's how to use the requests module:

    import requests as rq
    res = rq.get('http://www.example.com')
    
    print(res.content)
    print(res.status_code)
    
    0 讨论(0)
提交回复
热议问题