頁面的快照中有圖片和表格。 我將如何提取文章的正文?
如果您在表格中找到短語可以,您可以嘗試直接使用regular expressions,但更好的選擇是使用解析器並刪除所有標記。你可以使用Beautiful Soup做到這一點(你需要LXML太):
from bs4 import BeautifulSoup
# produces an iterable generator that returns the text of each tag in turn
gen = BeautifulSoup(markup_from_file, 'xml').stripped_strings
list_of_strings = [x for x in gen] # list comprehension generates list
' '.join(list_of_strings)
BeautifulSoup產生Unicode文本,因此,如果您需要更改的編碼,你可以這樣做:
list_of_strings = map(lambda x: x.encode('utf-8'),list_of_strings)
另外,美麗的湯可以幫助你更好地導航和選擇每個文件。如果你知道數據轉儲的編碼,這肯定會幫助它更快。作者還說,它在Python 3上運行速度更快。
谷歌搜索:'site:wikipedia.org word1 word2 word3 word4'。維基百科不會喜歡你抓取整個網站,我懷疑你是否希望在月底的帶寬賬單。 – 2012-04-06 04:31:07
你最好讓谷歌搜索你的網頁,然後搜索結果。只需驗證該網頁是否爲維基百科網址,並且該網頁中包含該詞組即可。 – aaronasterling 2012-04-06 04:31:52