Python xpath查询不返回文本值

2024-09-25 16:33:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用Python中的lxml模块从以下页面中获取数据:http://www.thehindu.com/todays-paper/with-afspa-india-has-failed-statute-amnesty/article7376286.ece。我想获取第一段中的文本,但是下面的代码返回null值

from lxml import html
import requests

page = requests.get('http://www.thehindu.com/todays-paper/with-afspa-india-has-failed-statute-amnesty/article7376286.ece')
tree = html.fromstring(page.text)
data = tree.xpath('//*[@id="left-column"]/div[6]/p[1]/text()')
print data

我不明白我做错了什么。如果有更好的方法来做我想做的事,请提出建议。在


Tags: comhttpwwwwithlxmlpaperhasfailed