使用XML抓取web,将td节点转换为val
我想通过谷歌搜索搜索点击数:使用XML抓取web,将td节点转换为val,xml,r,web-scraping,Xml,R,Web Scraping,我想通过谷歌搜索搜索点击数: require(XML) input <- "projektgebiet" url <- paste("https://www.google.at/search?q=", input, "&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:de:official&client=firefox-a", sep
require(XML)
input <- "projektgebiet"
url <- paste("https://www.google.at/search?q=",
input,
"&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:de:official&client=firefox-a",
sep = "")
CAINFO = paste(system.file(package="RCurl"), "/CurlSSL/ca-bundle.crt", sep = "")
script <- getURL(url, followlocation = TRUE, cainfo = CAINFO)
doc <- htmlParse(script)
xmlValue(getNodeSet(doc, "//td")[[6]])
require(XML)
输入您可以避免使用[[6]]
注意div
元素之一具有id
属性。
下面将分别返回两个子节点的内容,
没有连接它们
xpathSApply(doc, "//div[@id='subform_ctrl']/*", xmlValue)
# [1] "Erweiterte Suche" "Ungefähr 245.000 Ergebnisse"
您可以避免使用[[6]]
注意div
元素之一具有id
属性。
下面将分别返回两个子节点的内容,
没有连接它们
xpathSApply(doc, "//div[@id='subform_ctrl']/*", xmlValue)
# [1] "Erweiterte Suche" "Ungefähr 245.000 Ergebnisse"