我想获取 Wikipedia 文章的第一段。所以我正在使用 wikitools。
from wikitools import wiki
from wikitools import api
from wikitools import page
wikiobj = wiki.Wiki("http://en.wikipedia.org/w/api.php")
wikipage = page.Page(wikiobj, title="Office_Space")
wikidata = wikipage.getWikiText(True)
print wikidata
这里是 result of wikitools .在这个结果中有很多标签。我不想要这一切。
我只需要文章中的以下部分。 (从维基百科复制粘贴)。是否可以?谢谢。或者是否有其他可用的替代方法。太感谢了。
Office Space is a 1999 American comedy film satirizing work life in a typical 1990s software company. Written and directed by Mike Judge, it focuses on a handful of individuals fed up with their jobs portrayed by Ron Livingston, Jennifer Aniston, Gary Cole, David Herman, Ajay Naidu, and Diedrich Bader.
The film's sympathetic depiction of ordinary IT workers garnered a cult following within that field, but also addresses themes familiar to white collar employees in general.
Shot in Las Colinas and Austin, Texas, Office Space is based on Judge's Milton cartoon series. It was his first foray into live action film and second full length motion picture release.
请您参考如下方法:
wikipedia_utils 中的模板解析器(在 this article on how to scrape and parse Wikipedia 中引用)看起来它可以让您将 wikitools 返回的所有内容放入 Python 数据结构中,您可以从中提取您想要的位。
编辑:您可能还会发现 Python 库 mwlib如 this SO answer 中所述,可用于此目的.
