首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ImportError:没有名为BeautifulSoup的模块

ImportError:没有名为BeautifulSoup的模块
EN

Stack Overflow用户
提问于 2011-04-14 21:26:56
回答 8查看 126.1K关注 0票数 93

我已经使用easy_install安装了BeautifulSoup,并尝试运行以下脚本

代码语言:javascript
复制
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()

但不确定为什么会发生这种情况

代码语言:javascript
复制
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

你能帮帮我吗。谢谢

EN

回答 8

Stack Overflow用户

发布于 2012-06-11 11:05:03

尝试此from bs4 import BeautifulSoup

这可能是Beautiful Soup版本4和测试版的一个问题。我刚从主页上读到这篇文章。

票数 243
EN

Stack Overflow用户

发布于 2014-10-09 22:57:52

在Ubuntu 14.04上,我从apt-get安装了它,它工作得很好:

sudo apt-get install python-beautifulsoup

那就这样做:

from BeautifulSoup import BeautifulSoup

票数 22
EN

Stack Overflow用户

发布于 2016-01-27 16:37:21

试试这个,我的是这样工作的。要获取标签的任何数据,只需将"a“替换为您想要的标签。

代码语言:javascript
复制
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
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5663980

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档