daoxian zhou
daoxian zhou

Reputation: 1

rvest dowload fig from web xpath while chrome inspected not worked, why this in head of xml document will worked?

I wanna to download an image from url: target fig link xpath in chrome https://tophatter.com/lots/104461372

to extract :

https://images.tophatter.com/42c09f609e7a6a47c70e0e1ccf3a0bb6/large.jpg

while the xpath not worked: div[class='col-md-7 slot-images'] img

in Chrome browser > inspection > click the large fig, the Xpath shown in : //*[@id="lot-modal-content"]/div1/img

it`s in xml body part, not worked in rvest tutorial

library(rvest)
library(downloader)
library(dplyr)

url <- "https://tophatter.com/lots/104461372"
doc <- read_html(url)
doc <- xml2::read_html(url)

doc %>% html_nodes("div.col-md-7") %>% html_attr("class")
doc %>% html_nodes("div.col-md-7") %>% html_attr("src")

below is return 'col-md-7 slot-images' NA

Upvotes: 0

Views: 25

Answers (1)

daoxian zhou
daoxian zhou

Reputation: 1

here my solution ,after trail and error,i found the target jpg url in head part

a = doc %>% html_nodes("meta") %>% html_attrs
a = doc %>% html_nodes("meta") %>% html_attr("content") %>% na.omit
index = a %>% stringr::str_detect(".jpg") %>% which
a[index]

result screen shotcut

Upvotes: 0

Related Questions