我试图使用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
我不明白我做错了什么。如果有更好的方法来做我想做的事,请提出建议。在
尝试
//div[class='article-text']/p/text()
您可以按如下方式使用xpath:
相关问题 更多 >
编程相关推荐