Consider the following example of web scraping using R.
m <- "https://stackoverflow.com"
doc <- htmlParse(GET(m))
hello <- length(xpathSApply(doc, "//a/@href[contains(.,'stackoverflow')]"))
hello
[1] 48
The XPath function I use gives me the number of all links that contain the string "stackoverflow"
.
My goal is to replace the string "stackoverflow"
in the XPath function with a variable. Like this:
my_variable <- "stackoverflow"
hello <- length(xpathSApply(doc, "//a/@href[contains(.,my_variable)]"))
It doesn't work for now cause the data variable is considered a string. Can you please help me to explicit my_variable
is a variable?