只用了一周的 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