This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
I would like to extract the Forward Dividend from a site such as Yahoo Finance and insert it into Google Sheets.
Example 1:
For ticker symbol AAPL: https://finance.yahoo.com/quote/AAPL?p=AAPL
I would like the the Google Sheet field to return: 0.82
Example 2:
For the same symbol: https://www.streetinsider.com/dividend_history.php?q=aapl
I would like it to return the 0.82 amount from the table.
Is this even possible?
Since you mentioned you want to use the built-in IMPORT* functions, I will answer from that perspective.
As with most Sheets-based scraping, it depends on the site. The two sites you have given behave very differently. Let's examine them separately:
1: Yahoo Finance - Possible
We view source and see that 0.82 is located in a table. This lets us use IMPORTHTML:
=INDEX(
SPLIT(
VLOOKUP(
"Forward Dividend & Yield",
IMPORTHTML("https://finance.yahoo.com/quote/AAPL?p=AAPL", "table", 2),
2,
),
" "
),
1
)
Import table data
Get the dividend row
Extract the dividend yield value.
2: Street Insider - Not Possible
You might think that since the View Source lets us see the table in the browser, we should be able to use IMPORTHTML() again. Sadly this is not the case. The server-side seems to detect that you're not using a browser to access the .php, and it will display an empty page. Google sheets uses a different user agent from your own browser.
The only thing I can recommend if you need to use the IMPORT* functions is that you find a different site to pull the data from.
Related
One issue with using Google Forms to make a multiple choice quiz is that if a question has (for example) 3 points and 3 out of 5 correct answers, if a student only selects 2 of the 3 correct answers they will get 0 points, not 2.
The workaround for this is to use a checkboxGrid with only 1 column where each row is an answer choice.
Points can then be awarded for each correctly selected row.
I'm at a point where I want to create revision quizzes on the fly using this method, a snippet of my code that does this is here:
var question = questions[Math.floor(Math.random() * questions.length)];
var item = tasks.addCheckboxGridItem();
item.setTitle(question[1]);
item.setRows([ question[3],question[4],question[5],question[6],question,[7],question[8],question[9] ]);
item.setColumns(['Click if correct']);
I'm at a loss as to assign the correct answer and points to specific rows. I can see how to do this for a simple multiple choice question but not for this checkBoxgrid.
Issue:
GridItem and CheckboxGridItem currently don't support scoring. You cannot assign correct answers and points for these Items using Apps Script (e.g. createChoice(value, isCorrect), .setPoints(points)), nor retrieve this information (e.g. .isCorrectAnswer(), .getPoints(), .getScore()).
Feature Request:
There's currently a Feature Request related to this in Issue Tracker:
Allow user to get points and gat score of a GridItem
I'd suggest you to click the star on the top-left of the page in order to keep track of this and to help priorizing it.
Workaround:
In the meantime, your only options would be to use the UI instead, or to write a grading function yourself, as explained in the referenced issue:
- Find your Grid Item and grab it's ItemResponse.- Then get the response array.- Compare it to some grading function you create.- Return a score and use that number instead.
Of course, this workaround wouldn't add the scoring system to the Form itself, but it would be a way to handle quiz points programmatically.
I am a new user of Google Script and scripts in general.
My company has Office licences and for strategics reasons it wants to use google services.
My problem is that we extract from a software various data containing numbers. When we paste these datas on a spreadsheet the negatives numbers format is not recognized because they are like :
screenShot
I would like to apply the script only on a selection of active spreadsheet and the texte "1 234,56-" become a number "-1 234,56". The selection may contains positive number as "1 234,56".
Thank you for your help.
Best regards,
Anthony.
=VALUE(REGEXREPLACE(REGEXREPLACE(TEXT(A1; "0000.00"); "\s"; ""); "(.*?)-"; "-$1"))
This will first convert the number to a text string, then remove the whitespace character, then move the - sign in front of the number, and lastly convert it back to a numeric value.
Before:
1 234,56-
352,90
2 342,89-
24,0
45,00-
After (and you can use Sheets' number formats to further alter if needed):
−1234,56
352,9
−2342,89
24
−45
if you're range is not too long you can try something like that :
How to replace text in Google Spreadsheet using App Scripts?
i have the same probleme for a file of 5k line to remplace "." by "," it work but need a bit time :)
i hope this will help you
Best regards
New quizzing mode for google forms provides the scores in the form of a ratio with spaces in between (like this 5 / 7). However, the format of the cell is a number. So when I use dataRange.getValues(), I get only the first number (that is 5 in this example.) I tried setNumberFormat but received no permission error.
My goal is to somewhat get both numbers and actually complete the operation (5/7).
Thanks for your help.
I just found an answer. I used getDisplayValues() instead of getValues().
I am a total rookie and am trying to query data from a website and import it to Google docs spreadsheet. I have used firebug/firepath to find the xpath, when i paste the xpath into a cell =importxml(Url, query) it errors.
Here it is the url: http://www.sportfishingreport.com/pages/boatdetail.php?boat_id=781
Boat Trip Type Anglers Catch
03-22-2015 Full Day 21 48 Ocean Whitefish, 210 Rockfish, 21 Lingcod
Can someone help me write the xpath because the xpath that firepath tells me to write errors in google docs.
Thanks in advance, Jess
There are no tables in the source HTML of the second page you have indicated (that is, http://www.channelislandssportfishing.com/fish-counts). If anything, those tables are generated by Javascript, but then this content cannot be found by IMPORTXML, because it operates on the raw source HTML.
But what you get from Firepath is endlessly complicated anyway, because the tool tends to return path expressions that rely on positions of nodes, rather than actual values, or IDs, or names. If you look at the source HTML, the portion of HTML that contains "Erna B" looks like
Erna B
And there is in fact a trivial XPath expression that selects this content, because the href attribute value is unique. To have "Erna B" appear in a cell in Google Sheets, use
=IMPORTXML("http://www.channelislandssportfishing.com/fish-counts","//a[#href='/erna-b-sportfishing']")
For all other cells, look for similar properties that uniquely identify nodes, and turn those into path expressions.
I am trying to extract the latitudes and longitudes for the places listed on the right side of this page. I want to create a table like the following:
Place Latitude Longitude
Agarda 23.12604 87.19869
Ahanda 23.13099 87.18501
.....
.....
West-Sanabandh 23.24876 86.99941
Is it possible to do this in R without calling up the individual hyperlinks for "Agarda:, "Ahanda"... etc. one at a time?
The data appears on different pages. You can't get that data without requesting each page.
If R supports threads then you can call them up in parallel rather than one at a time.
It's possible to use RCurl to scrape each page in some type of loop or sapply. If you combine it with some regex and/or readHTMLTable (to identify the hyperlinks) then it's a relatively straightforward function.
Within RCurl, it's possible to create a multicurl which will do this in parallel, although given the number of queries involved, it might be just as easy to serialise it and put a small system sleep between queries.