'R: Errors when webscraping across mulitple tables with same URL

I'm fairly new to webscraping and having issues troubleshooting my code. At the moment I'm having different errors every time and don't really know where to continue. Currently looking into utilizing RSelenium but would greatly appreciate some advise and feedback on the code below.

Based my initial code on the following: R: How to web scrape a table across multiple pages with the same URL

library(xml2)
library(RCurl)
library(dplyr)
library(rvest)

i=1
table = list()
for (i in 1:15) {
  data=("https://www.forsvarsbygg.no/no/salg-av-eiendom/solgte-eiendommer/","?page=",i))
  page <- read_html(data)
  table1 <- page %>%
    html_nodes(xpath = "(//table)[2]") %>%
    html_table(header=T)
  i=i+1
  table1[[1]][[7]]=as.integer(gsub(",", "",table1[[1]][[7]]))
  table=bind_rows(table, table1)
  print(i)}

table$`ÅR`=as.Date(table$`ÅR`,format ="%Y")

Bellow are the errors i am recieving at the moment. I know its a lot, but i assume some of them are a result of previous errors. Any help would be greatly appreciated!

i=1

table = list() for (i in 1:15) {

  • data=("https://www.forsvarsbygg.no/no/salg-av-eiendom/solgte-eiendommer/","?page=",i))

Error: unexpected ',' in: "for (i in 1:15) { data=("https://www.forsvarsbygg.no/no/salg-av-eiendom/solgte-eiendommer/","

page <- read_html(data)

Error in UseMethod("read_xml") : no applicable method for 'read_xml' applied to an object of class "function"

table1 <- page %>%

  • html_nodes(xpath = "(//table)[2]") %>%
    
  • html_table(header=T)
    

Error in UseMethod("xml_find_all") : no applicable method for 'xml_find_all' applied to an object of class "function"

i=i+1 table1[[1]][[7]]=as.integer(gsub(",", "",table1[[1]][[7]]))

Error in is.factor(x) : object 'table1' not found

table=bind_rows(table, table1)

Error in list2(...) : object 'table1' not found

print(i)}

Error: unexpected '}' in " print(i)}"

table$ÃR=as.Date(table$ÃR,format ="%Y")



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source