【发布时间】:2014-08-25 22:48:34
【问题描述】:
我正在尝试编写将转到每个页面并从那里获取信息的代码。 网址 http://www.wikiart.org/en/claude-monet/mode/all-paintings-by-alphabet
我有输出所有href的代码。但它不起作用。
library(XML)
library(RCurl)
library(stringr)
tagrecode <- readHTMLTable ("http://www.wikiart.org/en/claude-monet/mode/all- paintings-by-alphabet")
tabla <- as.data.frame(tagrecode)
str(tabla)
names (tabla) <- c("name", "desc", "cat", "updated")
str(tabla)
res <- htmlParse ("http://www.wikiart.org/en/claude-monet/mode/all-paintings-by- alphabet")
enlaces <- getNodeSet (res, "//p[@class='pb5']/a/@href")
enlaces <- unlist(lapply(enlaces, as.character))
tabla$enlace <- paste("http://www.wikiart.org/en/claude-monet/mode/all-paintings-by- alphabet")
str(tabla)
lisurl <- tabla$enlace
fu1 <- function(url){
print(url)
pas1 <- htmlParse(url, useInternalNodes=T)
pas2 <- xpathSApply(pas1, "//p[@class='pb5']/a/@href")
}
urldef <- lapply(lisurl,fu1)
在我得到这个页面上所有图片的url列表后,我想去第二-第三-...-23页收集所有图片的url。
下一步 - 废弃每张图片的信息。 我有一个工作代码,我需要在一个通用代码中构建它。
library(XML)
url = "http://www.wikiart.org/en/claude-monet/camille-and-jean-monet-in-the-garden-at-argenteuil"
doc = htmlTreeParse(url, useInternalNodes=T)
pictureName <- xpathSApply(doc,"//h1[@itemprop='name']", xmlValue)
date <- xpathSApply(doc, "//span[@itemprop='dateCreated']", xmlValue)
author <- xpathSApply(doc, "//a[@itemprop='author']", xmlValue)
style <- xpathSApply(doc, "//span[@itemprop='style']", xmlValue)
genre <- xpathSApply(doc, "//span[@itemprop='genre']", xmlValue)
pictureName
date
author
style
genre
我们将不胜感激任何建议!
【问题讨论】:
标签: r web screen-scraping web-crawler