使用 Python 从维基百科 html 中提取文本 [英] Extract text from Wikipedia html using Python

查看:39
本文介绍了使用 Python 从维基百科 html 中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试寻找一种使用 python 提取维基百科文章正文的方法.我知道维基百科"库,但就我而言,我已经下载了 html 页面,我只需要提取文本.我不能使用那个库,因为我需要使用几年前下载的维基百科页面 html,所以我无法从头下载.

I am trying to look for a way to extract the main text of a Wikipedia article using python. I am aware of the "wikipedia" library, but in my case I already have downloaded the html page, and I just need to extract the text. I can't use that library because I need to use wikipedia page html that was downloaded some years ago so I can't download it from scratch.

是否有可以用于此目的的现成"解决方案?

Is there an "off the shelf" solution that I can use for this purpose?

推荐答案

尝试BeautifulSoup:

from bs4 import BeautifulSoup
import requests

respond = requests.get("http://pl.wikipedia.org/wiki/StackOverflow")
soup = BeautifulSoup(respond.text)
l = soup.find_all('p')
print l[0].text

这篇关于使用 Python 从维基百科 html 中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆