背景:我想使用rvest
在wikiart.org上为画家Paulo Uccello刮擦所有艺术品的所有细节。残局看起来像这样:
> names(uccello_dt)
[1] title year style genre media imgSRC infoSRC
问题:如果抓取尝试未按计划进行,我将退回character(0)
。这对我准确地理解从头开始获取character(0)
所采取的路径没有帮助。我想让我的尝试尝试输出特定的路径,以便更好地排除故障。
我尝试过的事情: 我使用Firefox,因此在每次尝试失败后,我都会返回Web检查器工具以确保我使用的是正确的CSS选择器/元素标记。我一直在保存rvest文档,以更好地了解其功能。这是一个反复试验,花费的时间比我想象的要长得多。这是许多失败之一的清理源:
library(tidyverse)
library(data.table)
library(rvest)
sample_url <-
read_html(
"https://www.wikiart.org/en/paolo-uccello/all-works#!#filterName:all-paintings-chronologically,resultType:detailed"
)
imgSrc <-
sample_url %>%
html_nodes(".wiki-detailed-item-container") %>% html_nodes(".masonry-detailed-artwork-item") %>% html_nodes("aside") %>% html_nodes(".wiki-layout-artist-image-wrapper") %>% html_nodes("img") %>%
html_attr("src") %>%
as.character()
title <-
sample_url %>%
html_nodes(".masonry-detailed-artwork-title") %>%
html_text() %>%
as.character()
谢谢。