Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/323.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
xpath和lxml用于Python获取数据_Python_Xpath_Lxml - Fatal编程技术网

xpath和lxml用于Python获取数据

xpath和lxml用于Python获取数据,python,xpath,lxml,Python,Xpath,Lxml,我从中什么也得不到。td元素不是sup元素的子元素。使用th和td是兄弟的事实: 谢谢它有我想要的数据,但它还包含另外两个元素。请参考上面编辑的代码。@vindex好的,请尝试以下操作://th[contains(span,“EPS”)]]/following sibling::td[1]/strong/text(),希望可以。 <th><span class="sic_edu_series_popup {keyword : 'EPS_STOCK'}">EPS</s

我从中什么也得不到。

td元素不是
sup
元素的子元素。使用
th
td
是兄弟的事实:


谢谢它有我想要的数据,但它还包含另外两个元素。请参考上面编辑的代码。@vindex好的,请尝试以下操作:
//th[contains(span,“EPS”)]]/following sibling::td[1]/strong/text()
,希望可以。
<th><span class="sic_edu_series_popup {keyword : 'EPS_STOCK'}">EPS</span>
          (SGD) <sup class="sic_legend">a
          , j

    </sup></th>
    <td><strong>1.89766</strong></td>
    <th><span class="sic_edu_series_popup {keyword : 'TRAILING_EPS_STOCK'}">Trailing EPS</span>
      (SGD) <sup class="sic_legend">e</sup></th>
    <td><strong>1.87198</strong></td>
    <th><span class="sic_edu_series_popup {keyword : 'NAV_STOCK'}">NAV</span>
      (SGD) <sup class="sic_legend">b</sup></th>
    <td><strong>18.5449</strong></td>
  </tr>
tree.xpath('//th[contains(normalize-space(span), "EPS")]/sup[@class = "sic_legend"]/td/text()')
//th[contains(span, "EPS")]/following-sibling::td/strong/text()