Error saying "Error in x$children[[1]] : subscript out of bounds" while web scrapping

0 votes

I trying to scrape sainsburys.co.uk, I'm running the next code in R

doc <- htmlTreeParse('http://www.sainsburys.co.uk/shop/gb/groceries/fruit-veg/all-fruit#langId=44&storeId=10151&catalogId=10122&categoryId=12545&parent_category_rn=12518&top_category=12518&pageSize=30&orderBy=FAVOURITES_FIRST&searchTerm')

rootNode <- xmlRoot(doc)

but I have this error:

Error in x$children[[1]] : subscript out of bounds
Nov 9, 2018 in Data Analytics by Ali
• 10,430 points
266 views

1 answer to this question.

0 votes

You could try the httr library:

library(XML)
library(httr)
url <- 'http://www.sainsburys.co.uk/shop/gb/groceries/fruit-veg/all-fruit#langId=44&storeId=10151&catalogId=10122&categoryId=12545&parent_category_rn=12518&top_category=12518&pageSize=30&orderBy=FAVOURITES_FIRST&searchTerm'
doc <- content(GET(url),type="text/html")
xmlValue(doc["//title"][[1]])
# [1] "All fruit | Sainsbury's"
answered Nov 9, 2018 by Maverick
• 10,040 points

Related Questions In Data Analytics

0 votes
1 answer

"subscript out of bounds" error in while executing simple R program

This is caused by trying to access ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 42,410 points
129 views
0 votes
1 answer

“subscript out of bounds” Error in r programming

This error is likely to occur when ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 42,410 points
2,129 views
0 votes
1 answer
0 votes
1 answer
0 votes
4 answers
0 votes
1 answer

Error saying "Error in df$item : object of type 'closure' is not subsettable" when trying to use arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,040 points
182 views
0 votes
1 answer

Error saying "Error in lag(x, 1) : unused argument (1)"

lag only works as expected with time-series ...READ MORE

answered Nov 16, 2018 in Data Analytics by Maverick
• 10,040 points
107 views