I have installed BeautifulSoup using easy_install and trying to run following script
from BeautifulSoup import BeautifulSoup
import re
doc = [\'
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
First install beautiful soup version 4. write command in the terminal window:
pip install beautifulsoup4
then import the BeutifulSoup library
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.
I had the same problem with eclipse on windows 10.
I installed it like recommende over the windows command window (cmd) with:
C:\Users\NAMEOFUSER\AppData\Local\Programs\Python\beautifulsoup4-4.8.2\setup.py install
BeautifulSoup was install like this in my python directory:
C:\Users\NAMEOFUSE\AppData\Local\Programs\Python\Python38\Lib\site-packages\beautifulsoup4-4.8.2-py3.8.egg
After manually coping the bs4 and EGG-INFO folders into the site-packages folder everything started to work, also the example:
from bs4 import BeautifulSoup
html = """
<html>
<body>
<p> Ich bin ein Absatz!</p>
</body>
</html>
"""
print(html)
soup = BeautifulSoup(html, 'html.parser')
print(soup.find_all("p"))
if you installed its this way(if you not, installing this way):
pip install beautifulsoup4
and if you used its this code(if you not, use this code):
from bs4 import BeautifulSoup
if you using windows system, check it if there are module, might saved different path its module
if you got two version of python, maybe my situation could help you
this is my situation
1-> mac osx
2-> i have two version python , (1) system default version 2.7 (2) manually installed version 3.6
3-> i have install the beautifulsoup4 with sudo pip install beautifulsoup4
4-> i run the python file with python3 /XXX/XX/XX.py
so this situation 3 and 4 are the key part, i have install beautifulsoup4 with "pip" but this module was installed for python verison 2.7, and i run the python file with "python3". so you should install beautifulsoup4 for the python 3.6;
with the sudo pip3 install beautifulsoup4
you can install the module for the python 3.6