ImportXML Xpath Query Return txt - xpath

I need to use Google Spreadsheet ImportXML return a value from this website...
http://www.e-go.com.au/calculatorAPI2?pickuppostcode=2000&pickupsuburb=SYDNEY+CITY&deliverypostcode=4000&deliverysuburb=BRISBANE&type=Carton&width=40&height=35&depth=65&weight=2&items=3
the website simply displays the below in text and code...
error=OK
eta=Overnight
price=64.69
I need to return the values after last line 'price=', being a newbee I'm struggling with xpath query (?) required to make this happens...
=importxml("url",?)
Your help is greatly appreciated.
Thank you in advance.
Regards

first of all, IMPORTXML() won't work because your webpage is not formatted correctly for XML, and google sheets doesn't like it.
All hope is not lost tho, as your output is so simple. you can simply load the whole output using IMPORTDATA() and then process within google sheets
have a look at the output of the following formulae (where the url is stored in A1)
=IMPORTDATA(A1)
=transpose(IMPORTDATA(A1))
=index(IMPORTDATA(A1),3,1) - IF there are always 3 results, and price will always be in the third one this will work
=filter(IMPORTDATA(A1),left(IMPORTDATA(A1),5)="price") - if the price can appear in any of the result lines, but always starting with "price"

Related

IMPORTXML Google Sheets for every 2nd node?

I'm having trouble trying to get a value with IMPORTXML in a google spreadsheet ...
I am using as xpath:
//*[contains(#class,"price") which returns me smoothly, ALL prices posted on a web page
The problem is that within that same class (and I don't know why, with dynamic ID's!) I have 2 nodes/prices: "Registered Customer Price" and "Non-Customer Price", which is the 2nd. value ... and the one I am interested in obtaining.
So, I wanted to apply it like this:
(//*[contains(#class,"price")])[2] and with this, I only get the 2nd price... but of the whole page!
(and not the 2nd. price of each and every item!)
I assume it is a "syntax" problem ... but no matter how many times I try it, I don't get the expected result!
Can you give me a hand with this?
Thanks in advance for any suggestion!
Just use :
//div[#class='price-box'][2]//span[#id]
Output :
EDIT : With IMPORTFROMWEB:
//h4[.="Precio unitario por unidad"]/following-sibling::span/span[#id]
EDIT 2 : More robust XPath :
//h4[.="Precio unitario por unidad"]/following-sibling::span[#class="price-excluding-tax"][count(following-sibling::*)=0]/span[#id]
try:
=FILTER(IMPORTXML(
"http://www.maxiconsumo.com/sucursal_villa_dominico/comestibles/aceites/aceite-girasol.html";
"//*[contains(#id,'price-including-tax')]"); MOD(ROW(INDIRECT("A1:A"&COUNTA(IMPORTXML(
"http://www.maxiconsumo.com/sucursal_villa_dominico/comestibles/aceites/aceite-girasol.html";
"//*[contains(#id,'price-including-tax')]")))); 2)=0)

What XPath expression should I use to fetch the number of likes and comments on a YouTube video?

I'm using the "IMPORTXML" function on Google Spreadsheets to get the number of likes and comments on any given YouTube video. However, I can't find the right XPath, and all I've tried return an empty value.
I used ChroPath to extract the XPath of the comments and likes count, but to no success.
This is the XPath that I've been using for amount of comments:
//yt-formatted-string[#class='count-text style-scope ytd-comments-header-renderer']
And this is for amount of likes:
//div[#id='info']//ytd-toggle-button-renderer[1]//a[1]//yt-icon-button[1]
When I try those it just says the content is empty. What is the correct XPath that I should be using to get the number of likes and comments?
You want to retrieve the number of likes of the video on YouTube.
You want to put the value to the Spreadsheet.
How about this formula? Please think of this as just one of several answers.
Sample formula:
=VALUE(IMPORTXML(A1,"//button[#title='I like this']/span"))
In this case, the cell "A1" is the URL like https://www.youtube.com/watch?v=###.
Xpath is //button[#title='I like this']/span".
Sample script of Google Apps Script:
As another method for retrieving the number of likes, if you use Advanced Google services of Google Apps Script, the sample script is as follows.
var count = YouTube.Videos.list("statistics", {id: "###"}).items[0].statistics.likeCount;
### is the video's ID.
References:
IMPORTXML
VALUE
Advanced Google services
Videos: list
If I misunderstood your question and this was not the result you want, I apologize.
for YT likes you could use:
=IF(ISNA(IMPORTXML("https://www.youtube.com/watch?v=MkgR0SxmMKo","(//*[contains(#class,'like-button-renderer-like-button')])[1]"))=TRUE,0,
IMPORTXML("https://www.youtube.com/watch?v=MkgR0SxmMKo","(//*[contains(#class,'like-button-renderer-like-button')])[1]"))

ImportXML function in Google Sheets produces error 'Imported content is empty'!

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!!
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

Xpath with contains() in importXML()

I've done dozens times, but now don't get what I'm doing wrong. I want to extract specific records, into 2 separate columns (I know that order wil not match), so I use:
//a/#href[contains(.; "github")]
and
//*[contains(text(); "Pricing:")]
But non of them is working - where my mistake?
(my sandbox: https://docs.google.com/spreadsheets/d/11Z3xybq_eYQvjn2-UBOomgeJxFrrsFoXKzF9yZSeASM/edit#gid=1841586203 with LT localle)
damn, those google sheet localles!!!... must be:
//a/#href[contains(., "github")]
and
//*[contains(text(), "Pricing:")]
I'll keep for further reference.

Correct xpath returns empty result

I want to scrape data from the table on this webpage http://www.changning.sh.cn/jact/front/front_mailpublist.action?sysid=9
Before writing a spider, I tested my Xpath expressions in Scrapy shell, but ran into one problem: Xpath can't get any text out of the table.
Say I want to extract the text LM2015122827458 in the upperleft cell, I used response.xpath("//tr[#class = 'tr_css']/td[1]/text()").extract(). Only an empty list was returned. I tried alternative Xpath expressions including the ones inspired by Chrome "copy Xpath," but had no luck. I even used response.xpath("//text()") to extract all the texts on the page to see if LM2015122827458 is there. It wasn't. So, is this a page that Xpath can't deal with? Or did I do something wrong? Thank you very much!
This Xpath is working fine for me:-
//tr[#class='tr_css'][1]/td[#class='text-center'][1]
Below code work in java is working fine for me :-
driver.get("http://www.changning.sh.cn/jact/front/front_mailpublist.action?sysid=9");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String a = driver.findElement(By.xpath("//tr[#class='tr_css'][1]/td[#class='text-center'][1]")).getText();
System.out.println(a);
Hope it will help you :)

Resources