gpt4 book ai didi

python - 导入错误 : No module named bs4 in Windows

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:56 25 4
gpt4 key购买 nike

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

from bs4 import BeautifulSoup
ImportError: No module named bs4

我尝试使用 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')

这个问题answer一定是因为我没有激活 virtualenv,然后安装 BeautifulSoup4。

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

最佳答案

我刚才遇到了同样的问题。感谢您的帖子和评论!根据@Martin Vseticka 的建议,我检查了我的 python 文件夹中是否有 pip.exe 文件。我同时运行 python 2.7 和 3.7。我没有在 python 2.7 文件夹中,但在 3.7.所以在命令行中我将目录更改为 pip.exe 文件所在的目录。然后我运行了“pip install BeautifulSoup4”,它成功了。请参阅随附的屏幕截图。 enter image description here

关于python - 导入错误 : No module named bs4 in Windows,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33331850/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com