0

I'd like to download the source code of an HTML. How can I do it?

I try to use read_html of the package xml2. But I had an error message.

test <- read_html('https://www.epicurious.com/search/Tropical%20Glazed%20Ham%20with%20Curried%20Pineapple%20Chutney')
Error in open.connection(x, "rb") : HTTP error 400.

From Mozilla, the source code can be seen through the source.

Wagner Jorge
  • 410
  • 2
  • 14

1 Answers1

0

read_html seems to time out for me when I use the url you provided, but for a workaround, save the raw html code on your file system with download.file and then read_html from the destination:

temp <- tempfile()

download.file('https://www.epicurious.com/search/Tropical%20Glazed%20Ham%20with%20Curried%20Pineapple%20Chutney',
              destfile = temp)

res <- readLines(temp)

library(xml2)

parsed <- read_html(temp)

avdeluca
  • 36
  • 4