YQL xpath 不够健壮
YQL xpath not robust enough
以前使用 n xpath python 并且从网页中提取数据是可靠的。现在我需要对同一个网页使用 YQL,但它不够健壮。
我要得到的是
1.最后(澳元)
2.关闭
3.Close (%)
4.累计成交量
来自 https://www.shareinvestor.com/fundamental/factsheet.html?counter=TPM.AX
我在 python 中使用的 xpath 如下:
xpath('//td[contains(., "Last")]/strong/text()')
xpath('//td[contains(., "Change")]/strong/text()')[0]
xpath('//td[contains(., "Change (%)")]/strong/text()')
xpath('//td[contains(., "Cumulative Volume")]/following-sibling::td[1]/text()')
部分 html 在这里
<tr>
<td rowspan="2" class="sic_lastdone">Last (AUD): <strong>6.750</strong></td>
<td class="sic_change">Change: <strong>-0.080</strong></td>
<td>High: <strong>6.920</strong></td>
<td rowspan="2" class="sic_remarks">
Remarks: <strong>-</strong>
</td>
</tr>
<tr>
<td class="sic_change">Change (%): <strong>-1.17</strong></td>
<td>Low: <strong>6.700</strong></td>
</tr>
<tr>
<tr>
<td>Cumulative Volume (share)</td>
<td class='sic_volume'>3,100,209</td>
<td>Cumulative Value</td>
<td class='sic_value'></td>
</tr>
但是当我想在YQL中申请时,它没有成功。它只适用于
select * from html where
url="https://www.shareinvestor.com/fundamental/factsheet.html?counter=TPM.AX"
and xpath="//td/strong"
它将获取大量数据。我想要一个特定的数据并且需要健壮,所以网页的变化,我的查询仍然 working.How 以获得健壮的 YQL xpath?
您应该避免根据可见文本构建 xpath。
我总是根据标签属性构建 xpath,因为它们通常不会改变。这使得 xpath 结果唯一并且不受 HTML.
中可见文本更改的影响
例如"Last (AUD):"值xpath:
//td[@class="sic_lastdone"]/strong/text()
以前使用 n xpath python 并且从网页中提取数据是可靠的。现在我需要对同一个网页使用 YQL,但它不够健壮。
我要得到的是 1.最后(澳元) 2.关闭 3.Close (%) 4.累计成交量 来自 https://www.shareinvestor.com/fundamental/factsheet.html?counter=TPM.AX 我在 python 中使用的 xpath 如下:
xpath('//td[contains(., "Last")]/strong/text()')
xpath('//td[contains(., "Change")]/strong/text()')[0]
xpath('//td[contains(., "Change (%)")]/strong/text()')
xpath('//td[contains(., "Cumulative Volume")]/following-sibling::td[1]/text()')
部分 html 在这里
<tr>
<td rowspan="2" class="sic_lastdone">Last (AUD): <strong>6.750</strong></td>
<td class="sic_change">Change: <strong>-0.080</strong></td>
<td>High: <strong>6.920</strong></td>
<td rowspan="2" class="sic_remarks">
Remarks: <strong>-</strong>
</td>
</tr>
<tr>
<td class="sic_change">Change (%): <strong>-1.17</strong></td>
<td>Low: <strong>6.700</strong></td>
</tr>
<tr>
<tr>
<td>Cumulative Volume (share)</td>
<td class='sic_volume'>3,100,209</td>
<td>Cumulative Value</td>
<td class='sic_value'></td>
</tr>
但是当我想在YQL中申请时,它没有成功。它只适用于
select * from html where
url="https://www.shareinvestor.com/fundamental/factsheet.html?counter=TPM.AX"
and xpath="//td/strong"
它将获取大量数据。我想要一个特定的数据并且需要健壮,所以网页的变化,我的查询仍然 working.How 以获得健壮的 YQL xpath?
您应该避免根据可见文本构建 xpath。
我总是根据标签属性构建 xpath,因为它们通常不会改变。这使得 xpath 结果唯一并且不受 HTML.
中可见文本更改的影响例如"Last (AUD):"值xpath:
//td[@class="sic_lastdone"]/strong/text()