0
votes

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
Which value you want to retrieve? Since it is dynamic class, the class attribute changes anytime, you need to use another scraping technique to retrieve the data. - Ben
i need to retrieve the current price. can you advise the name of another scaping technique and method? - OOI YI YONG

1 Answers

0
votes

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.

enter image description here

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.