使用BeautifulSoup从网页中提取文本

你好,
我想在一组网页上提取所有单词,然后将其存储在
大词典.然后,我希望获取最常见的清单
正在考虑的语言的单词.因此,我下面的代码读取
页面-http://news.bbc.co.uk/welsh/hi/newsi...00/7420967.stm
威尔士语言页面.我希望最常见的是建立1000个
在威尔士语中使用的单词.我遇到的问题是
汤.
u'doctypes html public' - // W3C // DTD HTML 4.0 Transitional // en en"" http://
www.w3.org/tr/rec-html40/loose.dtd"''
和 -
有什么建议,我如何克服这个问题?
谢谢,
巴里.
这是我的代码 -
导入Urllib
导入urllib2
来自美丽的小组
#proxy_support = urllib2.proxyhandler({" http":" http://
999.999.999.999:8080"})
#opener = urllib2.build_opener(proxy_support)
#urllib2.install_opener(开启器)
page = urllib2.urlopen('http://news.bbc.co.uk/welsh/hi/newsid_7420000/
newsID_7420900/7420967.stm')
汤=美丽的套(页)
pagetext = soup.findall(text = true)
打印pagetext

# 回答1


2008年5月27日星期二03:01:30 -0700,Magnus.Moraberg写道:
只需从文档正文中提取文本即可.
body_texts = soup.body(text = true)
要求BBC生产越来越小的HTML. ;-) http://validator.w3.org/报告"不允许在这里'Body'标签"之类的错误
或关闭标签而无需打开标签,依此类推.
再见,
marc'blackjack'rintsch
# 回答2


在27 Maj,12:54,Marc'Blackjack'Rintsch 只需从文档正文中提取文本即可.
body_texts = soup.body(text = true)
要求BBC生产越来越小的HTML. ;-) http://validator.w3.org/reports bugs之类
或关闭标签而无需打开标签,依此类推.
再见,
马克"二十一点" Rintsch
太谢谢了!
# 回答3


5月27日,5:01*am,magnus.morab ...@gmail.com写道:
作为替代数据点,您可以尝试使用HTMLStripper示例
在pyparsing wiki上:http://pyparsing.wikispaces.com/spac...tmlstripper.py.py
- 保罗

标签: python

添加新评论