我已经使用easy_install安装了BeautifulSoup,并尝试运行以下脚本
from BeautifulSoup import BeautifulSoup
import re
doc = ['<html><head><title>Page title</title></head>',
'<body><p id="firstpara" align="center">This is paragraph <b>one</b>.',
'<p id="secondpara" align="blah">This is paragraph <b>two</b>.',
'</html>']
soup = BeautifulSoup(''.join(doc))
print soup.prettify()
但不确定为什么会发生这种情况
Traceback (most recent call last):
File "C:\Python27\reading and writing xml file from web1.py", line 49, in <module>
from BeautifulSoup import BeautifulSoup
ImportError: No module named BeautifulSoup
你能帮帮我吗。谢谢
发布于 2012-06-11 11:05:03
尝试此from bs4 import BeautifulSoup
这可能是Beautiful Soup版本4和测试版的一个问题。我刚从主页上读到这篇文章。
发布于 2014-10-09 22:57:52
在Ubuntu 14.04上,我从apt-get安装了它,它工作得很好:
sudo apt-get install python-beautifulsoup
那就这样做:
from BeautifulSoup import BeautifulSoup
发布于 2016-01-27 16:37:21
试试这个,我的是这样工作的。要获取标签的任何数据,只需将"a“替换为您想要的标签。
from bs4 import BeautifulSoup as bs
import urllib
url="http://currentaffairs.gktoday.in/month/current-affairs-january-2015"
soup = bs(urllib.urlopen(url))
for link in soup.findAll('a'):
print link.string
https://stackoverflow.com/questions/5663980
复制相似问题