Writing your first scraping script

Let's start to write our first scraping using R. In previous sections, we have already created XPath rules and URLs that we are interested in. We will start by collecting category counts and information about how many articles there are for each article: 

  • First of all, we have called an rvest library using the library function. We should load the rvest library using the following command:
     library(rvest)
  • Now we need to create NULL variables, because we are going to save count of articles for each categories and the name of the categories.
  • For this purpose, we are creating category and count variables:
     #creating NULL variables     category<- NULL     count <- NULL
  • Now it's time to create a variable that includes ...

Get R Web Scraping Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.