r-web-scraping-cheat-sheet | Guide , reference and cheatsheet on web | Learning library
kandi X-RAY | r-web-scraping-cheat-sheet Summary
kandi X-RAY | r-web-scraping-cheat-sheet Summary
Guide, reference and cheatsheet on web scraping using rvest, httr and Rselenium.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of r-web-scraping-cheat-sheet
r-web-scraping-cheat-sheet Key Features
r-web-scraping-cheat-sheet Examples and Code Snippets
Community Discussions
Trending Discussions on r-web-scraping-cheat-sheet
QUESTION
I am new to the web scraping topic with R and Rvest. With rvest you can scrape static HTML but I have found out that rvest struggeling to scrape data from heavy JS based Sites.
I found some articels or blog posts but they seems depricated like https://awesomeopensource.com/project/yusuzech/r-web-scraping-cheat-sheet
In my case i want scrape odds from Sport Betting Sites but with rvest and SelectorGadget this isnt possible in my Opinion because of the JS.
There is an Articel from 2018 about scraping Odds from PaddyPower(https://www.r-bloggers.com/how-to-scrape-data-from-a-javascript-website-with-r/) but this is out dated too, because PhantomJS isnt available anymore. RSelenium seems to be an option but the repo has many issues https://github.com/ropensci/RSelenium.
So is it possible to work with RSelenium in its current state or what options do I have instead of RSelenium?
kind regards
...ANSWER
Answered 2020-Sep-13 at 12:24I've had no problems using RSelenium
with the help of the wdman
package, which allowed me to just not bother with Docker. wdman
also fetches all binaries you need if they aren't already available. It's nice magic.
Here's a simple script to spin up a Selenium instance with Chrome, open a site, get the contents as xml and then close it all down again.
QUESTION
I want to scrape historical results of South African LOTTO draws (especially Total Pool Size, Total Sales, etc.) from the South African National Lottery website. By default one sees links to results for the last ten draws, or one can select a date range to pull up a larger set of links to draws (which will still display only ten per page).
Hovering in the browser over a link e.g. 'LOTTO DRAW 2012' we see javascript:void();
so it is clear that the draw results will be rendered using Javascript. Reading advice on an R Web Scraping Cheat Sheet, I realized that I needed to open Google Chrome Developer tools, then open Network tab, and then click the link to the draw 'LOTTO DRAW 2012'. When I did so, I could see that this url is being called with an initiator
When I right-click on the initiator and select 'Copy Response', I can see the data I need inside a 'drawDetails' object in what appears to be JSON code.
...ANSWER
Answered 2020-Apr-13 at 20:57You are right - the contents on the page are updated by javascript via an ajax request. The server returns a json string in response to an http POST request. With POST requests, the server's response is determined not only by the url you request, but by the body of the message you send to the server. In this case, your body is a simple form with 3 fields: gameName
, which is always LOTTO
, isAjax
which is always true
, and drawNumber
, which is the field you want to vary.
If you are using httr
, you specify these fields as a named list in the body
parameter of the POST
function.
Once you have the response for each draw, you will want to parse the json into an R-friendly format such as a list or data frame using a library such as jsonlite
. From looking at the structure of this particular json, it makes most sense to extract the component $data$drawDetails
and make that a one-row dataframe. This will allow you to bind several draws together into a single data frame.
Here is a function that does all that for you:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install r-web-scraping-cheat-sheet
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page