xpath google sheet importxml

时光总嘲笑我的痴心妄想 提交于 2020-07-08 03:00:40

问题


this is the link i want to do my importxml on

https://sg.finance.yahoo.com/quote/D05.SI

<div class="dot-label Pos(r) Fz(13px) Fw(500) D(ib) Ta(c)"><span>Current</span><!-- react-text: 18 -->&nbsp;<!-- /react-text --><span>25.08</span></div>

i would like to use importxml to retrieve the value 25.08.

=IMPORTXML("https://sg.finance.yahoo.com/quote/D05.SI","//*[@class='dot-label Pos(r) Fz(13px) Fw(500) D(ib) Ta(c)']//span")

but it always return #NA, please advise the correct syntax or link and the reasons so i can have some understanding.


回答1:


Using id attribute selector is always safer than using class attribute selector, because they are using class binding and it gets changed frequently. I found the closest DOM that has id attribute, and lookup until the current price is scraped.

You should try this xpath:

=INDEX(IMPORTXML("https://sg.finance.yahoo.com/quote/D05.SI","//div[@id='quote-header-info']/div[last()]/div[1]"),1)

But sometimes the layout / DOM structure get changed, you might need to check and update the xpath to ensure that it correctly scrape the value that you wanted.



来源:https://stackoverflow.com/questions/47752009/xpath-google-sheet-importxml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!