Can we replace a sentence or a word in a html

Hi all,

I have couple of file in html. I need replace certain words with another word. For example I have a word called "name". I need to replace them with "Names". Can we do this in one go in R? Please advice.

Actually, in the same file itself it should get replaced. Is it possible?

You can just use the tidyverse stringr package for this.

# read_html("path to your file")
# str_replace_all(string, pattern, replacement)
# write_html(x, "path to your file")
library("tidyverse")
path <- "/Users/Enno/Documents/htmlfile.html"
file <- read_html(path)
file <- str_replace_all(file, "name", "Names")
write_html(file, path)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.