Problem in stalling packages

I have installed a number of packages and have successfully be using them.

 

For some reason beautifulsoup4 is not recognised when I try use it, I 'import bs4' into a py file and the module is not recongised, but I have installed the package through the project interpreter.

 

I'm running PyCharm on a windows environment and using python 3.4.4.

 

Can someone help?

6 comments
Comment actions Permalink

I just gave it a try and it worked fine. Is your issue only that the code isn't "recognized", or does it also fail during execution?

0
Comment actions Permalink

On the first line when I type in 'import bs4', and thats fine. 

 

But when I go to use bs4() in my code, the 'bs4'  on the first line has a red zigzaged line underneath, which suggests no module named bs4 is found. I also tried variations (beautifulsoup4 and beautifulsoup).  I even tired to run the code, but an ImportError arises, 'ImportError: No Module named 'bs4'. Below is the code:

from b4s import BeautifulSoup
import urllib.request
url = 'http://www.dr-chuck/page1.htm'
html = urllib.request.urlopen(str(url)).read()
soup = BeautifulSoup(html)
tags = soup('a')
for tag in tags:
print(tag.get('href', None))

 

0
Comment actions Permalink

You have "from b4s" instead of "bs4".

0
Comment actions Permalink

Hi Paul,

As you can probably tell, I'm a novice. Only been programming for a couple of months.

 

I made the following changes, but I now get a different error message. Can you please advise on what I should do?

 

import bs4
import urllib.request

url = 'http://www.dr-chuck/page1.htm'
html = urllib.request.urlopen(str(url)).read()
soup = bs4.BeautifulSoup(html)
tags = soup('a')
for tag in tags:
print(tag.get('href', None))


#Below is the error message:


C:\Python34\python.exe "C:\Users\Hemesh\PycharmProjects\untitled\Python for Informatics\play.py"
C:\Python34\lib\site-packages\bs4\__init__.py:166: UserWarning: No parser was explicitly specified,
so I'm using the best available HTML parser for this system ("html.parser"). This usually isn't a
problem, but if you run this code on another system, or in a different virtual environment, it may
use a different parser and behave differently.

To get rid of this warning, change this:

BeautifulSoup([your markup])

to this:

BeautifulSoup([your markup], "html.parser")

markup_type=markup_type))

Process finished with exit code 0

0
Comment actions Permalink

I'm not much of a beautifulsoup user, but a bit of googling showed that you just need to do what it suggests. That is, change your line:

soup = bs4.BeautifulSoup(html)

...to:

soup = bs4.BeautifulSoup(html, "html.parser")

...to explicitly name which parser you want to use.

0
Comment actions Permalink

Thanks Paul!

That has done the trick.

0

Please sign in to leave a comment.