ImportXML XPath advice - xpath

I'm trying to scrape this webpage:
https://www.nextory.se/bok/heroine-mons-kallentoft-markus-lutteman/9789188345844
I want to scrapte the title, the cover photo, the book description, and the book info in the bottom.
I tried for 2 hours figuring out the correct Xpath formula for Google Sheets...
There is for example the division "single__Book__textcontent" that should give me the text from this div, but cannot get it to work in sheets!
Tried this one without success:
=IMPORTXML(A1,"//div[#class='div.single__Book__textcontent']")

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:

How to find the correct Xpath to get importxml function work

I'm trying 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://www.superama.com.mx/catalogo/d-frutas-verduras/f-frutas/l-naranja-limon-y-citricos/mandarina-por-kilo/0000000003029
and I'm trying to bring the id="lblPrice" which in this case is $24.90
I was trying this formula but I'm getting NA
=IMPORTXML("https://www.superama.com.mx/catalogo/d-frutas-verduras/f-frutas/l-naranja-limon-y-citricos/mandarina-por-kilo/0000000003029","//*[#id="lblPrice"]")
IMOPORTXML/Google Sheets does not support scraping of JavaScript elements.

Using Google Sheets for web scraping. Need the correct xpath for IMPORTXML function

There is a google sheet containing a list of MPN's (manufacturer part numbers). Trying to scrape a site called wikiarms for the UPC Codes when I have the MPN for an item.
I have the correct formula for doing this on another site.
=IMPORTXML("http://gun.deals/search/apachesolr_search/"&B1,"//dd/a[../../dt[contains(text(),'UPC')]]|//dd/span[../../dt[contains(text(),'UPC')]]")
Trying to figure out what the correct xpath to complete this formula. Some videos I have watch said to open the page in Chrome and use inspector to select and copy the xpath to complete the importxml function. I tried this with no luck.
Sample
Visit https://www.wikiarms.com/guns?q=20071
In the table there is a button "available in 6 stores" click that to reveal the list. The UPC should be listed after the MPN.
If I copy the xpath in Chrome this is the result
/html/body/div[1]/div/div/div[2]/div/div/div[2]/div[2]/table/tbody/tr[2]/td[5]
=IMPORTXML("https://www.wikiarms.com/guns?q="&B2,"xpath here")
What do I have to add at the end of this formula to pull in the UPC code? I will be using this formula to pull in UPC code for about 1000 items.
Thank you for your help.
Using your sample link, try
=IMPORTXML("https://www.wikiarms.com/guns?q=20071","//td[#class='upc']/a/#title")
and see if it works for you.

ImportXML parse error - Wikipedia scraping with excel sheet

I'm trying to scrape little data into an excel sheet from Wikipedia website using the ImportXML formula.
The XPath code I copied which I got it from the browser.
Here is the Wikipedia page. https://en.wikipedia.org/wiki/Chicago
Scraping the Latitude and longitude which is present on the page.
Screenshot:
This is the code that I get from the browser XPath selector.
//*[#id="mw-content-text"]/div/table[1]/tbody/tr[11]/td/span[1]/span/a/span[1]/span/span[1]
Can you help me with the code and help me where I'm doing the wrong?
try:
=INDEX(IMPORTXML("https://en.wikipedia.org/wiki/Chicago", "//span[#class='geo-dms']"), 1)

My importXML + xPath + Soundcloud playlist Not Working

So How To Use importXML By Google Docs Spreadsheet Plus xPath To Help Me Copy Soundcloud Playlist Track Title?
Today I'm looking for a solution on how to copy the Track Title of tracks inside a Soundcloud Playlist/Compilation.
I searched around and discovered importXML function offered by Google Docs Spreadsheet. While digging further about the importXML function, I discovered about xPath.
Great combination! I thought.
So I quickly get my hands on the tools and tested it, and it's great! I've extracted some data. And so I decided that I'm ready to implement the tool and use it with Soundcloud.
But when I tried to implement the syntax, I got an error saying Import Internal Error
The Syntax Is
=IMPORTXML(A1,"//div[#class='sc-media-content']/a[#title]")
<div class="sc-media-content"> is the div that holds the Track Title of the song, that is enclosed within an anchor tag with title attribute.
Here is the html block for it;
<div class="sc-media-content">
<a class="soundTitle__title sc-link-dark sc-truncate " href="/seven-lions/velvetine-the-great-divide?in=thedubstepgod/sets/melodic-dubstep-chillstep" title="Velvetine - The Great Divide (Seven Lions Remix)">
Velvetine - The Great Divide (Seven Lions Remix)
</a>
What I'm trying to extract is the Velvetine - The Great Divide (Seven Lions Remix). A1 is the cell where the Soundcloud Playlist Link is pasted into.
Other Syntax I've Tried
I've tried other syntax too, like;
=IMPORTXML(A1,"//div[#class='sc-media-content']/title")
As suggested here
=IMPORTXML(A1,"//div[#class='sc-media-content']/#title") From an answer found here, though it wasn't an accepted answer.
So what am I doing wrong? How could I copy those soundcloud playlist title to my Google Docs Spreadsheet using xPath?
UPDATE
Based from the answer given by TGH, this should work //div[#class='sc-media-content']/a/text().
But, the problem is that the div block that we're looking for is not in the source code. I did a view source code on the Playlist's page and the div block is not there. All I'm seeing is JavaScripts. So JS is loading the div blocks/classes.
So another question might be needed to help solve this one
How to use xPath with JavaScript loaded html elements?
Try the following
//div[#class='sc-media-content']/a/text()
Or if you want to grab it from the title do this
//div[#class='sc-media-content']/a/#title
I tested it here and it seems to work. Pasted your html, but had to close the div manually.
http://www.unit-testing.net/Xpath

Resources