ImportError:Windows中没有名为bs4的模块

We'*_*ere 3 python captcha image

我正在尝试创建一个脚本来从我的网站下载验证码。我认为代码可以正常工作,但不会出现该错误,当我在cmd中运行它时(我使用的是Windows,而不是Linux),我收到以下信息:

from bs4 import BeautifulSoup
ImportError: No module named bs4
Run Code Online (Sandbox Code Playgroud)

我尝试使用,pip install BeautifulSoup4 但是在安装时收到语法错误。

这是脚本:

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')
Run Code Online (Sandbox Code Playgroud)

根据此答案的问题一定是由于我尚未激活virtualenv,然后安装BeautifulSoup4。

另外,我认为这些信息不会有任何帮助,但是我将python文本保存在notepad.py中,并使用cmd运行它。

Sim*_*one 5

直到刚才我也遇到了同样的问题。感谢您的帖子和评论!根据@Martin Vseticka的建议,我检查了我的python文件夹中是否有pip.exe文件。我同时运行python 2.7和3.7。我没有在python 2.7文件夹中,但是在3.7中。因此,在命令行中,我将目录更改为pip.exe文件所在的目录。然后我运行了“ pip install BeautifulSoup4”,它起作用了。请参阅随附的屏幕截图。在此处输入图片说明