Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html Python:xpath从span中的元素获取文本_Html_Xml_Python 2.7_Xpath - Fatal编程技术网

Html Python:xpath从span中的元素获取文本

Html Python:xpath从span中的元素获取文本,html,xml,python-2.7,xpath,Html,Xml,Python 2.7,Xpath,我有以下HTML: <span class="time" data-time="2014-11-06T22:00:00.000+0000">10'</span> 我遇到的问题是,这会为这个特定元素返回一个空列表。元素是一个在站点上动态更新的计时器,它看起来不像text()调用在做任何事情 感谢您的帮助 明白了:在text()调用之前添加了一个额外的“/”。所以它读作“…/div[3]/span//text()”,它选择所有后代文本。在花了相当长的时间搜索之后(在发布之前

我有以下HTML:

<span class="time" data-time="2014-11-06T22:00:00.000+0000">10'</span>
我遇到的问题是,这会为这个特定元素返回一个空列表。元素是一个在站点上动态更新的计时器,它看起来不像text()调用在做任何事情


感谢您的帮助

明白了:在text()调用之前添加了一个额外的“/”。所以它读作“…/div[3]/span//text()”,它选择所有后代文本。在花了相当长的时间搜索之后(在发布之前,相信我),我最终在这里找到了帮助


我将把这个留给以后帮助其他人。

有人知道为什么在这种情况下需要额外的斜杠吗?
import requests
from lxml import html

page=requests.get('http://www.url.com/data')
tree=html.fromstring(page.text)
empty=tree.xpath('//*[@id="stuff"]/div[1]/div[6]/div[1]/div/div/div/div[3]/span/text()')