1
votes

Here is the ImportXML formula I am using:

=IMPORTXML("https://finance.yahoo.com/quote/RY.TO/profile",K6)

Cell K6 contains the following xpath query:

//*[@id="Col1-0-Profile-Proxy"]/section/div[1]/div/div/p[2]/strong[1]

I got the xpath query by using the Copy XPath function in Google Chrome (e.g. after inspecting the element I am interested in).

The element I am interested in is the Sector associated with the Royal Bank (e.g. Financial Services)

Any help would be appreciated. Many thanks!!

1
Does my answer solve your problem? Feel free to upvote/accept. - wp78de

1 Answers

2
votes

Using the Copy XPath function is a handy feature. However, the suggested query is usually clumsy and sometimes does not yield the desired result. Here is an alternative approach:

//span[.='Sector']/following-sibling::strong[1]

Select the span that has the innerHtml "Sector" and then select the following strong sibling; finally, we can select the /text() directly too like this:

=IMPORTXML($A$10;"//span[.='Sector']/following-sibling::strong[1]/text()")

which returns: Financial Services