Importxml Imported Content Empty - xpath

I encounter the error message imported content is empty when I use the formula below in google spreadsheet.
=IMPORTXML("https://www.moh.gov.sg/content/moh_web/home/pressRoom.html", "//div[#class='article highlight']/h3/a/#title")
I am trying to import the list of press release title on the webpage.
What am I doing wrong?

So this issue is not your formula or XML in this particular case, its that the content is loaded using jQuery, so you need to figure out where or what the url is that actually holds your content.

Related

Import XML of span element fails with #N/A

finally decided to sign up to stackoverflow because of this. So I´d be super grateful about a solution!
I´m trying to get a number of a <span> element. Here is an image of the data box I´m trying to scrape from. It´s on this page: https://de.marketscreener.com/kurs/aktie/SNOWFLAKE-INC-112440376/analystenerwartungen/
The relevant Xpath is //*[#id="highcharts-0oywbsk-200"]/div[2]/div/span/span
I´m trying: =IMPORTXML("https://de.marketscreener.com/kurs/aktie/SNOWFLAKE-INC-112440376/analystenerwartungen/"),"//div[2]/div/span/span")
I´m ignoring the #id-element, this works pretty well with many elements on the same page, but in this case not at all. I ignore the id, because I can´t use it as it changes on every page. Is this ok?
Google Sheets always gives me a #N/A error?! Any idea how to scrape that number?
disabling JavaScript reveals what you can scrape:

Find the Xpath to get data with importxml function

I want to use ImportXML function in google sheets in order to bring some prices into my google sheet, how to find the correct Xpath for this ?
This is the URL: https://super.walmart.com.mx/verduras/aguacate-hass-extra-por-kilo/00000000003354
and im trying to bring the price, in this case is $39.90
I was trying this formula but im getting NA (imported content is empty)
=IMPORTXML("https://super.walmart.com.mx/verduras/aguacate-hass-extra-por-kilo/00000000003354","//*[#id="scrollToTopComponent"]/section/div[1]/div[2]/div[2]/div[3]/h4/text()[1]")
Thanks
IMPORTXML does not work on Javascript content
You can verify that that the URL https://super.walmart.com.mx/verduras/aguacate-hass-extra-por-kilo/00000000003354 content loads via Javascript by
going on your Browser settings
Disable / block Javascript
Refresh your URL
See the following:
So, unfortunately you cannot use IMPORTXML to get the content of this URL.

Data table not importing from morningstar

I am trying to take data from https://financials.morningstar.com/ratios/r.html?t=0P0000032S&culture=en&platform=sal and use the values in the table in a Google sheet. This is table1 when I inspect the element but when I use:
=IMPORTHTML("https://financials.morningstar.com/ratios/r.html?t=0P0000032S&culture=en&platform=sal","table",1)
on google sheets, it says the imported content is empty? Any help on how to import this data?
I've tried importhtml using table number references found when I inspected the page.
unfortunately, that won't be possible because the site is controlled by JavaScript and Google Sheets can't understand/import JS. you can test this simply by disabling JS for a given link and you will see a blank page:

Import data from ebay to google spreadsheet using IMPORTXML

I'm trying to Import a table from "https://www.ebay.com/itm/100-NEW-ALTERNATOR-VW-GOLF-GTI-GL-GLS-1-8T-1-8-2L-99-06-90A-1-YR-WARRANTY-13852/301364941754?fits=Model%3AJetta&hash=item462ac013ba:g:v7oAAOSw~YRagU4N&vxp=mtr" to a Google Spread sheet using =IMPORTXML function, The Formula I was using as below,
A1 = https://www.ebay.com/itm/100-NEW-ALTERNATOR-VW-GOLF-GTI-GL-GLS-1-8T-1-8-2L-99-06-90A-1-YR-WARRANTY-13852/301364941754?fits=Model%3AJetta&hash=item462ac013ba:g:v7oAAOSw~YRagU4N&vxp=mtr
A2 = //*[#id="w1-20ctbl"]
A3 = =IMPORTXML(A1,A2)
But it returns nothing and It says "Imported content is empty."
Can Somebody help me, I'm new to google sheet scripting and I'll really grateful if somebody can help me.
waiting to hearing from somebody....
Thanks
You cannot access the pictured table using IMPORTXML or any built-in Google Sheets formula because the table is generated when a user visits the website.
If you look at the page source, you'll see that the table does not exist. IMPORTPATH looks at this page source, which is the content before javascript rendering by the browser. When you "inspect" an element in your browser, it's inspecting the content after the javascript has been rendered.
Unfortunately, there is not a simple way to get the data you're looking for. You'll have to find or build your own scraping tool. Be careful not to violate eBay terms of use or any local laws.

Can't get the data using importXML from Dynamic Web Page?

The website is : https://www.futbin.com/18/player/2600/Ayhan/
I inspect the element and get the XPath which is: //*[#id="ps-lowest-1"]
Then I use:
=IMPORTXML("https://www.futbin.com/18/player/2600/Ayhan/","//*[#id='ps-lowest-1']")
To get the data which should be 2000
But instead it only shows: - on the sheet. No errors just doesn't show the data that I want it to. Is there anyway to get the data that I need?
Thanks
The Sheets command importXML reads only the HTML source of the page without executing any JavaScript on it. As you can see yourself by using "view source" in the browser, the source indeed has "-" in that span:
<span class="price_big_right">
<span id="ps-lowest-1">-</span>
</span>
The actual numbers are loaded by some JavaScript file which then inserts them in that span. Neither importXML nor other Sheets functions can retrieve dynamically inserted data.
Sometimes, after inspecting the JS files, one can uncover the URL of source of data and try to import that; but this is a tedious reverse engineering exercise for each particular site.

Resources