Reputation: 3280
I need to get the name of a youtube video from the link. Typically I can do something like this to for a wikipedia page:
doc <- xmlTreeParse("http://en.wikipedia.org/wiki/Google", useInternalNodes=TRUE)
xpathSApply(doc,'//title',xmlValue)
but the following doesn't work for youtube:
doc <- xmlTreeParse("https://www.youtube.com/watch?v=YuOBzWF0Aws", useInternalNodes=TRUE)
Gives error.
Any help will be much appreciated.
Upvotes: 2
Views: 110
Reputation: 30425
The XML
library cannot download secured links. You can use RCurl
and getURL
to download the file and then parse with the XML
library or in this case ask for a non secure version (http
):
library(XML)
appURL <- "http://www.youtube.com/watch?v=YuOBzWF0Aws"
doc <- htmlParse(appURL)
sapply(doc['//*[@id="eow-title"]'], xmlGetAttr, name = "title")
> sapply(doc['//*[@id="eow-title"]'], xmlGetAttr, name = "title")
[1] "If Google was a Guy"
Upvotes: 3