1

只用了一周的 Python 时间。我已经使用 easy_install 安装了 BeautifulSoup4。安装似乎没问题,因为在 Python shell 中并使用 from bs4 import BeautifulSoup 时没有错误。

尝试在我从 win7 上的 cmd 控制台调用的脚本中使用“from bs4 import BeautifulSoup”时出现错误“python C:\Users\Ryan\Desktop\precipitation.py”

从 bs4 导入 BeautifulSoup

#precipitation.py:

import urllib.request
import re
from bs4 import BeautifulSoup


#htmlfile = urllib.request.urlopen("http://www.wunderground.com/history/airport/KYIP/2013/6/16/DailyHistory.html6")
#htmltext = htmlfile.read()
#regex = b'<td class="indent"><span>Precipitation</span></td>\n<td><span class="nobr"><span class="b">(.+?)</span>''
#pattern = re.compile(regex)

print('Who made the Soup?!')

运行脚本时出错:python C:\Users\Ryan\Desktop\precipitation.py

Traceback (most recent call last):
File "C:\Users\Ryan\Desktop\precipitation.py", line 3, in
    from bs4 import BeautifulSoup
File "C:\Users\Ryan\Desktop\precipitation.py", line 1, in <module>
    from bs4 import BeautifulSoup
ImportError: cannot import name BeautifulSoup
4

1 回答 1

0

至少尝试安装python3.5+。Python3.3 于 2013 年(7 年前!)发布。

看来您正在Windows上运行。在这种情况下,您可能只需下载 anaconda,这将使您的生活更轻松:https ://anaconda.org/anaconda/beautifulsoup4 。

参考:

于 2020-08-25T00:58:25.220 回答