我正在从 html 文件中读取文本并进行一些分析。这些 .html 文件是新闻文章。
代码:
html = open(filepath,'r').read()
raw = nltk.clean_html(html)
raw.unidecode(item.decode('utf8'))
现在我只想要文章内容而不是广告、标题等其余文本。我怎样才能在 python 中相对准确地做到这一点?
我知道一些工具,如 Jsoup(一个 java api)和bolier,但我想在 python 中这样做。我可以找到一些使用bs4的技术,但仅限于一种类型的页面。我有来自众多来源的新闻页面。此外,缺乏任何示例代码示例。
我在 python 中寻找与http://www.psl.cs.columbia.edu/wp-content/uploads/2011/03/3463-WWWJ.pdf完全一样的东西。
编辑: 为了更好地理解,请编写示例代码以提取以下链接的内容http://www.nytimes.com/2015/05/19/health/study-finds-dense-breast-tissue-isnt-always -a-high-cancer-risk.html?src=me&ref=general