ImportError: No module named BeautifulSoup
Solution 1:
Try this from bs4 import BeautifulSoup
This might be a problem with Beautiful Soup, version 4, and the beta days. I just read this from the homepage.
Solution 2:
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
Solution 3:
Try This, Mine worked this way. To get any data of tag just replace the "a" with the tag you want.
from bs4 import BeautifulSoup as bs
import urllib
url="http://currentaffairs.gktoday.in/month/current-affairs-january-2015"
soup = bs(urllib.urlopen(url))
for link in soup.findAll('a'):
print link.string
Solution 4:
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)
Solution 5:
First install beautiful soup version 4. write command in the terminal window:
pip install beautifulsoup4
then import the BeutifulSoup library