I have installed BeautifulSoup using easy_install and trying to run following script
from BeautifulSoup import BeautifulSoup
import re
doc = [\'
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
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)