Python XPath查询未返回文本值 [英] Python xpath query not returning text value
本文介绍了Python XPath查询未返回文本值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Python中的lxml模块从以下页面抓取数据:
I am trying to scrape data from the following page using the lxml module in Python: http://www.thehindu.com/todays-paper/with-afspa-india-has-failed-statute-amnesty/article7376286.ece. I want to get the text in the first paragraph, but the following code is returning null value
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
我不明白我在做什么错.请提出是否有更好的方法来做我想做的事情.
I don't understand what I'm doing wrong here. Please suggest if there are better ways of doing what I'm trying to do.
推荐答案
您可以按如下所示使用xpath:
you can use xpath as follow :
div[@class='article-text']/p[1]/text()
这篇关于Python XPath查询未返回文本值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文