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
Related
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 trying to sum values using sumifs but I am getting an error. Went throught several website but I guess I don't have a good understanding of how SUMIF works.
Right now I have a sheet with a registry date(C), a price per weeek(G) and a end date(D).
I would want to calculate the earning every week.
So I created another sheet with every week of the year.
=SUMIFS(Clients!G2:G;A5;>=Clients!C2:C;A5;<=Clients!D2:D)
I am not using coma as a separator as my google sheet is not in english.
I am trying to sum the incomes if the date on the second sheet is between the starting date and the end date. But I keep getting errors and I don't really unerstand why.
Thanks
I found an formula which look to be working.
=SUMIFS(Clients!G2:G;Clients!C2:C;"<="&A5;Clients!D2:D;">="&A5)
I guess that it was not working because I was letting A5 to incremente.
Problem solved.
Thanks for your help.
Find out more here on Google's post about =SUMIFS().
Sample usage
SUMIFS(A1:A10, B1:B10, ">20")
SUMIFS(A1:A10, B1:B10, ">20", C1:C10, "<30")
SUMIFS(C1:C100, E1:E100, "Yes")
Syntax
SUMIFS(sum_range, criteria_range1, criterion1, [criteria_range2, criterion2, ...])
sum_range – The range to be summed.
criteria_range1 – The range to be checked against criterion1.
criterion1 – The pattern or test to apply to criteria_range1.
criteria_range2, criterion2, … (OPTIONAL) – Additional ranges and criteria to be checked.
=COUNTIFS((Tab1!C2:Tab1!C250),"*sam*") & ((Tab1!B2:Tab1!B250), ">1-Nov-2020")
In the above formula, I'm trying to get the count of 'person names whose name is sam and the value which is past 1-Nov-2020.
While trying to fetch the count using the above formula, it is showing Formula parse error.
Please analyze and tell where might I went wrong.
You need to correct your syntax to:
=COUNTIFS('Tab1'!C2:C9,"sam", 'Tab1'!B2:B9,">1-Nov-2020")
Please read more on how the COUNTIFS function work.
EDIT (following OP's comment)
The correct syntax would be
COUNTIFS(criteria_range1, criterion1, [criteria_range2, …], [criterion2, …]) meaning:
=COUNTIFS('Tab1'!C2:C9,"sam", 'Tab1'!B2:B9,">1-Nov-2020", 'Tab1'!B2:B9,">=1-11-2020")
BUT
Since you refer to dates 1-Nov-2020 is the same as 1-11-2020.
So you only need
=COUNTIFS('Tab1'!C2:C9,"sam", 'Tab1'!B2:B9,">=1-11-2020")
OR
=COUNTIFS('Tab1'!C2:C9,"sam", 'Tab1'!B2:B9,">=1-Nov-2020")
I'm trying to use the IMPORTXML function on Google Sheets.
For example: =IMPORTXML("https://www.tiktok.com/#charlidamelio?lang=en", XMLPATH) should return "54.3M"
I used the Chrome inspector to copy the xpath, which gives me:
/html/body/div[1]/div/div[2]/div/div[1]/div/header/h2[1]/strong[2]
When I try this in Google Sheets it returns an error: #N/A (Import Content is Empty).
P.S. I'm open to other ways to get the data I need into the google sheet, it doesn't have to use the IMPORTXML function.
How about this answer?
In this answer, IMPORTXML and REGEXEXTRACT are used. And also, it supposes that the URL of https://www.tiktok.com/#charlidamelio?lang=en is put in a cell "A1".
Pattern 1:
In this pattern, "followerCount" is retrieved.
Sample formula:
=REGEXEXTRACT(IMPORTXML(A1,"//script[#id='__NEXT_DATA__']"),"followerCount"":(\d+)")
"followerCount" is retrieved from the script.
In this case, when =VALUE(REGEXEXTRACT(IMPORTXML(A1,"//script[#id='__NEXT_DATA__']"),"followerCount"":(\d+)")) is used, the retrieved value can be used as the number.
Result:
Pattern 2:
In this pattern, "followerCount" is retrieved.
Sample formula:
=REGEXEXTRACT(IMPORTXML(A1,"//meta[#name='description']/#content")," ([\w\d.]+) Fans")
The value of "54.4M Fans" is retrieved from the metadata.
Result:
References:
IMPORTXML
REGEXEXTRACT
The data on the page is delivered as follows:
https://int.soccerway.com/international/europe/uefa-champions-league/20192020/group-stage/r54142/
1 - Below each schedule is a link to the match.
2 - I would like to import all data at once.
3 - The result I seek would be as follows:
4 - Import separately, I can, but as they are separate formulas, it takes a long time, I would like a way to import all at once, for a formula only if it were possible.
5 - The Xpath are:
"//*[#class='date no-repetition']"
"//*[#class='score-time status']/a"
"//*[#class='score-time status']/a/#href"
6 - An important detail, I indicated the 'score-time status' because there are games that appear as 'score-time score' but these cannot be imported.
7 - There is another detail that complicates, the time comes with spaces between the sign of :, so for him I use the =SUBSTITUTE(," ","")
Is there any way to do this that I want?
I've tried using ={;;} to import the data, but can't make calls to more than two =IMPORTXML().
I also tried for =IMPORTHML() but it can't fetch the links from each of the below-hours matches and the date also appears in only one of the games...
How about this answer? I think that there are several answers for your situation. So please think of this as just one of several possible answers.
xpath:
Unfortunately, I couldn't find the xpath for directly retrieving the 3 values in your question. So in this answer, the following xpath are used.
Date: //td[#class='date no-repetition']/span
Time: //td[#class='score-time status']/a/span
URL: //td[#class='score-time status']/a/#href
Sample formula:
=ARRAYFORMULA({IMPORTXML(A1,"//td[#class='date no-repetition']/span"),IMPORTXML(A1,"//td[#class='score-time status']/a/span"),"https://"&IMPORTXML(A1,"//td[#class='score-time status']/a/#href")})
In this formula, the URL of https://int.soccerway.com/international/europe/uefa-champions-league/20192020/group-stage/r54142/ is put to the cell "A1".
Retrieved 3 values are put to the column "A", "B" and "C".
Result:
Note:
In above case, I think that the time zone might be the place when the values are retrieved by IMPORTXML.
If you want to change the timezone to your own Spreadsheet, how about the following sample formula?
=ARRAYFORMULA({IMPORTXML(A1,"//td[#class='date no-repetition']/span/#data-value")/86400+DATE(1970,1,1),IMPORTXML(A1,"//td[#class='date no-repetition']/span/#data-value")/86400+DATE(1970,1,1),"https://"&IMPORTXML(A1,"//td[#class='score-time status']/a/#href")})
In this case, please set the format to the column "A" and "B".
In above formula, the date and time is retrieved the unix time. This value is converted to the serial number. So the converted value can be used as the date and time at Spreadsheet.
References:
IMPORTXML
ARRAYFORMULA
If this was not the direction you want, I apologize.