i'm trying to retrieve travel distance and travel time from this XML
URL :https://dev.virtualearth.net/REST/v1/Routes/DistanceMatrix?origins=30.90232,30.17693&destinations=31.10171,30.3131&travelMode=driving&o=xml&key=AngGTts45jKAUVLSgsymA4Vho1GJfd2PN5V11RenWFRjhfa5gRwexx5HSbNQYz-2
i tried to TEXTJOIN(",",FALSE,IMPORTXML(E9,"//*"))
but hard to extract , so any help with this to allocate and extract Travel distance and time
in excel using webservice and filterxml works fine but in google sheets i couldn't find solution
and this result for XML
<Copyright>Copyright © 2022 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
<BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>
<StatusCode>200</StatusCode>
<StatusDescription>OK</StatusDescription>
<AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
<TraceId>8fb637a9728f4476837032284c19ea52|DU0000274E|0.0.0.0|DU0000049D</TraceId>
<ResourceSets>
<ResourceSet>
<EstimatedTotal>1</EstimatedTotal>
<Resources>
<Resource xsi:type="DistanceMatrix">
<Origins>
<Coordinate>
<Latitude>30.90232</Latitude>
<Longitude>30.17693</Longitude>
</Coordinate>
</Origins>
<Destinations>
<Coordinate>
<Latitude>31.10171</Latitude>
<Longitude>30.3131</Longitude>
</Coordinate>
</Destinations>
<Results>
<Distance>
<DepartureTime xsi:nil="true"/>
<OriginIndex>0</OriginIndex>
<DestinationIndex>0</DestinationIndex>
<TravelDistance>42.261</TravelDistance>
<TravelDuration>78.5</TravelDuration>
<TotalWalkDuration>0</TotalWalkDuration>
</Distance>
</Results>
</Resource>
</Resources>
</ResourceSet>
</ResourceSets>
</Response>```
I believe your goal is as follows.
From i'm trying to retrieve travel distance and travel time from this XML URL, you want to retrieve the values of TravelDistance and TravelDuration from the XML data using IMPORTXML.
In this case, how about the following sample formula?
Sample formula:
=IMPORTXML(A1,"//*[local-name()='TravelDistance' or local-name()='TravelDuration']")
In this case, the cell "A1" has the URL shown in your question.
Result:
For example, when you want to retrieve the values to the columns, please use TRANSPOSE like =TRANSPOSE(IMPORTXML(A1,"//*[local-name()='TravelDistance' or local-name()='TravelDuration']")).
Related
I am trying to use importxml to import the "52 Week Avg Return" number (in this case it is -10.02%) on this website: https://www.marketwatch.com/investing/fund/vwelx
I'm not sure what to add to this formula to correct it. Any help would be appreciated!
enter image description here
I am using this formula:
=IMPORTXML("https://www.marketwatch.com/investing/fund/vwelx", "//span[#class='primary']")
In your situation, how about the following XPath?
Sample XPath:
//li[#class='kv__item' and ./small[text()='52 Week Avg Return']]/span
or
//li[#class='kv__item' and position()=last()]/span
Sample formula:
=IMPORTXML(A1,"//li[#class='kv__item' and ./small[text()='52 Week Avg Return']]/span")
or
=IMPORTXML(A1,"//li[#class='kv__item' and position()=last()]/span")
In this case, please set the URL of https://www.marketwatch.com/investing/fund/vwelx to the cell "A1".
Testing:
Note:
This XPath is for your provided URL of https://www.marketwatch.com/investing/fund/vwelx. So, when you change the URL, this might not be able to be used. And also, when the specification of the server side is changed, this might not be able to be used. Please be careful about this.
Reference:
IMPORTXML
Right now I am scraping certain Productinformation from bol.com.
The product data is getting scraped. But for each 30 products, about 5 are either scraping incomplete data, for instance the EAN is missing, while its in the same content block as normal or it just gives N/A. While there is information.
Any tips?
Ps. This is my current formula: =importxml(C27;"//*[#id='mainContent']/div/div[1]/div[5]/div[1]/div[4]/div/div/div[1]/div/div[1]/dl")
C27 is the URL. (https://www.bol.com/nl/nl/p/adroitgoods-hondenriem-180-cm-hondenlijn-looplijn-hondenlijn-reflecterend-rood-lange-lijn-hond/9300000101425619/)
It should import the following product information:
EAN
Kleur
Materiaal
Maat
Reflecterend
Speciaal voor hardlopen
Type uitlaatriem
Verpakkingsinhoud
try:
=INDEX(TRIM(IMPORTxML(A1, "//dl[#class='specs__list']/div")))
I'm trying add easy updating prices into a google sheet.
I need the market price from
//*[#id="app"]/div/section[2]/section/div[1]/section[3]/div/section[1]/ul/li[1]/span[2]
https://www.tcgplayer.com/product/242811/pokemon-celebrations-celebrations-elite-trainer-box?Language=English
I need it to display just the one number from the XPath to a cell, and I can't seem to figure out where I am going wrong. I've been using the IMPORTXML function and it won't return a value.
=IMPORTXML(A2,"//*[#id='app']/div/section[2]/section/div[1]/section[3]/div/section[1]/ul/li[1]/span[2]")
where A2 is the URL.
In your situation, it seems that the value of the market price cannot be directly retrieved from the URL of https://www.tcgplayer.com/product/242811/pokemon-celebrations-celebrations-elite-trainer-box?Language=English. But, fortunately, it seems that that value can be directly retrieved from the endpoint of API. So, how about the following sample formula?
Sample formula:
=REGEXEXTRACT(JOIN(",",IMPORTDATA(A1)),"marketPrice:(.+?),")*1
or
=REGEXEXTRACT(QUERY(TRANSPOSE(IMPORTDATA(A1)),"WHERE Col1 matches 'marketPrice.+'"),"marketPrice:(.+)")*1
The cell "A1" has the URL of https://mpapi.tcgplayer.com/v2/product/242811/details.
In the case of https://www.tcgplayer.com/product/242811/pokemon-celebrations-celebrations-elite-trainer-box?Language=English, please use 242811 from the URL to the endpoint of API like https://mpapi.tcgplayer.com/v2/product/242811/details.
Result:
Note:
The value from the URL is JSON data. In this case, the following custom function can be also used. In this case, please copy and paste the following script to the script editor of Spreadsheet and save the script. And please put a custom function of =SAMPLE("url") to a cell.
const SAMPLE = url => JSON.parse(UrlFetchApp.fetch(url).getContentText()).marketPrice;
References:
IMPORTDATA
REGEXEXTRACT
Custom Functions in Google Sheets
it's not possible to scrape JS content into google sheets:
I am using Google Sheets as a mileage tracker to calculate the distance from my home to various addresses. This formula had been working for me for a few months, but recently stopped:
=ROUND((importxml("https://maps.googleapis.com/maps/api/distancematrix/xml?&origins="&"My+Home+Address"&"&destinations="&A1&"&sensor=false&units=imperial&alternatives=false&key=MY_API_KEY","/DistanceMatrixResponse/row/element/distance/value")/1609.344)*2,1)
I am using my own valid API key and have verified that the query works outside of Google Sheets. The funny thing is, if I change "/distance/value" to "/duration/value", Sheets returns a response just fine.
Here's what the returned XML looks like for the Distance Matrix:
<DistanceMatrixResponse>
<status>OK</status>
<origin_address>Home Address, USA</origin_address>
<destination_address>Destination Address, USA</destination_address>
<row>
<element>
<status>OK</status>
<duration>
<value>1983</value>
<text>33 mins</text>
</duration>
<distance>
<value>29971</value>
<text>18.6 mi</text>
</distance>
</element>
</row>
</DistanceMatrixResponse>
How do I get the "distance" to work again??
This works for me:
=IMPORTXML("https://maps.googleapis.com/maps/api/distancematrix/xml?&origins="&B1&"&destinations="&B2&"&sensor=false&alternatives=false&key="&B3,"/DistanceMatrixResponse/row/element/distance/text")
BTW, if you get rid of units=imperial, it defaults to metric and you won't have to /1609.344
I am trying to capture elements of an qmd file (that is xml markup) using Google Sheets importxml. Based on the reply to my question Google ImportXML from QGIS metadata file I am able to capture the primary tag.
=transpose(IMPORTXML("https://drive.google.com/uc?id=1AI2C8hQnSOuuoyJXizYBszGmpMXW8xxT&export=download","//authid"))
However I can't access some elements
<spatialrefsys>
<proj4>+proj=utm +zone=55 +south +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs</proj4>
<srsid>2449</srsid>
<srid>28355</srid>
<authid>EPSG:28355</authid>
<description>GDA94 / MGA zone 55</description>
<projectionacronym>utm</projectionacronym>
<ellipsoidacronym>GRS80</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</crs>
<extent>
<spatial minx="322783.17999999999301508" minz="0" crs="EPSG:28355" maxx="337384.35999999998603016" miny="8170597.66000000014901161" maxz="0" dimensions="2" maxy="8181833.33999999985098839"/>
<temporal>
<period>
<start></start>
<end></end>
</period>
</temporal>
</extent>
From the //extent I want minx, maxx
for XPath I have tried "//extent", "//extent/spatial", "//extent/spatial[#*]" and "#minx"
but get no result.
You want to retrieve the values of maxx and minx using IMPORTXML().
If my understanding is correct, how about this modification?
Modified formula:
=TRANSPOSE(IMPORTXML(A1,"//spatial/#maxx | //spatial/#minx"))
https://drive.google.com/uc?id=1AI2C8hQnSOuuoyJXizYBszGmpMXW8xxT&export=download is put in the cell "A1".
In this case, //spatial/#maxx | //spatial/#minx is used as the xpath.
Attibute values can be retrieved with #.
When you want to use these values as the number, you can use this.
If you want to use the values as the text, for example, how about the following formula?
=TRANSPOSE(ARRAYFORMULA(TEXT(IMPORTXML(A1,"//spatial/#maxx | //spatial/#minx"),"0.0000000000")))
Result:
Reference:
IMPORTXML
If I misunderstood your question and this was not the result you want, I apologize.