importXML xpath to google sheets returns #N/A - google-sheets

Under the following span class I am looking to extract the number (416) 123-1234. This number is written after data-number or at the end of the span.
<span class="_Xbe _ZWk kno-fv"> ## The Unique ID is _Xbe _ZWk kno-fv
<a class="fl r-idASUKPhOV34" href="#" data-number="+14161231234" data-pstn-
-call-url="" title="Call via Hangouts" jsaction="r.oVdbr2mIpA8"
data-rtid="idASUKPhOV34" jsl="$t t-6xg4lalHw8M;$x 0;" data-ved="0ahUKEwiDtKTG-snZAhUDzIMKHcntCfAQkAgImAEoADAU">(416) 123-1234</a></span>
The problem comes from the XPATH, I am not specifying the right xpath, I tried to copy xpath from the source code and it returned #N/A. My best guess is the following xpath with importxml, though it still returns #N/A.
=IMPORTXML("https://www.google.com/search?q="&A10,"//span[#class='_Xbe _ZWk kno-fv']/a/#href")
How can I write XPATH to extract the number in either form?

Related

GoogleSheet IMPORTHTML Link in Button

I use a googlesheet and IMPORTHTML to get the content of this page :
https://meteor.dsac.fr/documentation.php
It works fine, except the last column : the return value is "Consulter", however I would like to get the link instead (eg: https://meteor.dsac.aviation-civile.gouv.fr/meteor-externe/#communication/18280)
Is there a way to do that with that function?
Thanks
In the current stage, IMPORTHTML cannot retrieve the attribute of the tag. So, for example, how about the following sample formula?
Sample formula:
=QUERY({IMPORTHTML("https://meteor.dsac.fr/documentation.php","table",1),{"";IMPORTXML("https://meteor.dsac.fr/documentation.php","//td[4]/a/#href")}},"SELECT Col1,Col2,Col3,Col5")
In this sample formula, in order to retrieve the URLs instead of the value of "Consulter", IMPORTXML is used.
Testing:
When this formula is used, the following result is obtained.
References:
IMPORTHTML
IMPORTXML

HTML concatenate functions producing strange outputs in Google Sheets

I am trying to build some concatenate functions to work with HTML.
The functions are almost there, but when I copy the result from Google Sheets the formula doesn't pick up the dynanic value from another cell:
=CONCATENATE("<div class=""audio-container"" style=""display:flex;justify-content:center;align-items:center;""><audio controls><source src="",B3,"" type=""audio/mpeg""></source></audio></div>")
FORMULA OUTPUT: <div class="audio-container" style="display:flex;justify-content:center;align-items:center;"><audio controls><source src=",B3," type="audio/mpeg"></source></audio></div>
ISSUE: The B6 CELL reference containg the string download.mp3 is not inserting
I think it is something to do with the HTML double quotes, even though they seem to output correctly, but the cell reference seems to be ignored and is being recognized as a string instead.
You were almost there. I got:
=CONCATENATE("<div class=""audio-container"" style=""display:flex;justify-content:center;align-items:center;""><audio controls><source src=""";B1;""" type=""audio/mpeg""></source></audio></div>")
The output I get is: <div class="audio-container" style="display:flex;justify-content:center;align-items:center;"><audio controls><source src="download.mp3" type="audio/mpeg"></source></audio></div>
You were right, the problem was in the double quotes. You had to add a third one. Look at the part ...src=""";B1;""" type=.... That fixed everything.

How to get child nodes through importxml xpath query?

I'm trying to get the seperate <td>'s to show up in Google Sheet of a <tr> that I'm importing through IMPORTXML.
This code should get my match data based on the match ID I provide, and my player ID. I feel that simply adding /* or /td to end of Xpath should work, but that's the end of my knowledge.
I tried: adding /*, /td and other to end of xPath Query but doesn't seem to work.
Even disabled JavaScript and inspected website again but to no avail.
FORMULA:
=IMPORTXML("https://www.dotabuff.com/matches/5011379854";"//tr[contains(#class,'9764136')]")
Also tried:
=IMPORTXML("https://www.dotabuff.com/matches/5011379854";"//td[parent::tr[contains(#class,'9764136')]]")
Which only gives the first of all the /td's and not the rest.
Current outputis all mushed together:
"19LemthTop (Off)ZeusCoreTop (Off) Roaminglost27108.7k127933650626.5k-183-/-5m7m21m31m"
The output that I want is separate <td> on separate lines:
"19
LemthTop (Off)ZeusCoreTop (Off) Roaminglost
2
7
10
8.7k
127
9
336
506
26.5k
-
183
-/-
5m7m21m31m"
Issue and workaround:
Although I have tried to parse the values for each row, unfortunately, it seemed that td cannot be directly parsed using a xpath with IMPORTXML as each row. But fortunately, each table can be retrieved by IMPORTHTML and also each tab can be accessed. Using them, how about the following workaround?
Retrieve a table from the URL using IMPORTHTML.
Retrieve a row including the name corresponding to 9764136 you want using a query.
Modified formula:
=TRANSPOSE(SPLIT(TEXTJOIN("#",TRUE,QUERY(IMPORTHTML(A1,"table",1), "where Col4 contains '"&IMPORTXML(A1,"//a[contains(#href,'9764136')]")&"'", 0)),"#",TRUE,TRUE))
The URL of https://www.dotabuff.com/matches/5011379854 is put to the cell "A1".
After the table was retrieved, the row is retrieved from the table by the query.
The important point of this workaround is the methodology. I think that there are various formulas for retrieving the value. So please think of above sample formula as just one of them.
Result:
Note:
If you use above formula for other URL, an error might occur. Please be careful this.
References:
IMPORTHTML
IMPORTXML
TEXTJOIN
SPLIT
TRANSPOSE

Limit the importxml to a defined span

Currently I am using a transpose and then another column to count the results and give me what I want. But because Tanaike is awesome and helped me on another section, I am trying to wrap my head around what he did and apply it to this.
Starting with this URL in A1,
https://www.zillow.com/homedetails/307-N-Rosedale-Ave-Tulsa-OK-74127/22151896_zpid/
This is the formula in A2:
=If($A$1:A="","",Transpose(importxml($A1:$A,"//span[#class='snl phone']")))
Based on the listing sometimes there are three phone numbers, sometimes four, and sometimes eight that get spread across as many columns as needed.
I am looking for the Property Owner phone number. This is the ELEMENT from the inspection.
<div class="info flat-star-ratings sig-col" id="yui_3_18_1_2_1506365934526_2361"> <span class="snl name notranslate">Property Owner</span> <span class="snl phone" id="yui_3_18_1_2_1506365934526_2360">(918) 740-1698 </span> </div>
So I tried this, and it comes up content is empty. I was thinking to look at the div class info flat, then within that the snl phone, and stop before the /end of span.
=importXML(B17,"//div[#class='info flat-star-ratings sig-col']//span[#class='snl phone']/#span")
What I really need is ONLY the property owner phone number with 95% or greater accuracy.
How about this modification of XPath query?
Modified XPath query :
=importxml(A1,"//div[#class='info flat-star-ratings sig-col']//span[#class='snl phone']")
Result :
If this is not data you want, I'm sorry.
Edit :
4th and 8th number are the same. Is my understanding correct? If it's no problem. Please put URL and a following formula to "A1" and "A2", respectively.
=QUERY(ARRAYFORMULA(IF(IMPORTXML(A1,"//div[#class='info flat-star-ratings sig-col']//span[#class='snl name notranslate']")="Property Owner",IMPORTXML(A1,"//div[#class='info flat-star-ratings sig-col']//span[#class='snl phone']"), "")),"Select * where Col1<>''")
Result :

Parsing text content in ColdFusion

I am attempting to parse text from a <cfoutput query="...">. I am interested in finding the number of times every word in the text is displayed. For example:
"My name is Bob and I like to Bob".
should result in
Bob - 2
Name - 1
etc, etc, etc.
I take my <cfoutput> from a twitter RSS feed. Here is my code:
<blink>
<cfset feedurl="http://twitter.com/statuses/user_timeline/47847839.rss" />
<cftry>
<cffeed source="#feedurl#" properties="feedmeta" query="feeditems" />
<cfcatch></cfcatch>
</cftry>
<ol>
<cfoutput query="feeditems">
#content# #id# <br><br>
</cfoutput>
</ol>
</blink>
I output a pretty great ordered list, but I can't figure out for the life of me how to parse the content and list how many times each word is used.
Thanks for any help you can provide, I am new to these forums!
You can find a solution here:
http://www.coldfusionjedi.com/index.cfm/2007/8/2/Counting-Word-Instances-in-a-String
Basically, split the string up using regex and then loop over the results. There are some darn good comments here as well.

Resources