Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named bs4 in Windows

I am trying to create a script to download the captcha from my website. I think the code works except from that error, when I run it in cmd (I am using windows not Linux) I receive the following:

from bs4 import BeautifulSoup
ImportError: No module named bs4

I tried using pip install BeautifulSoup4 but then I receive a syntax error at install.

Here is the script:

from bs4 import BeautifulSoup
import urllib2
import urllib

url = "https://example.com"
content = urllib2.urlopen(url)
soup = BeautifulSoup(content)
img = soup.find('img',id ='imgCaptcha')
print img
urllib.urlretrieve(urlparse.urljoin(url, img['src']), 'captcha.bmp')

The problem according to this answer must be due to the fact I have not activated the virtualenv, and THEN install BeautifulSoup4.

I don't think this information will be of any help but I saved my python text in a notepad.py and the run it using cmd.

like image 931
We're All Mad Here Avatar asked Mar 14 '23 08:03

We're All Mad Here


1 Answers

I had the same problem until a moment ago. Thanks for the post and comments! According to @Martin Vseticka 's suggestion I checked if I have the pip.exe file in my python folders. I run python 2.7 and 3.7 simultaneously. I didn't have it in the python 2.7 folder but in the 3.7. So in the command line I changed the directory to where the pip.exe file was located. Then I ran "pip install BeautifulSoup4" and it worked. See enclosed screen shot. enter image description here

like image 169
Simone Avatar answered Mar 25 '23 04:03

Simone