我试着上网刮擦。我有"HTTP错误403“错误。
library(rvest)
library(dplyr)
link <- "https://www.hepsiburada.com/lg-70nano756pa-70-177-ekran-uydu-alicili-4k-ultra-hd-smart-led-tv-p-HBCV00000YCM48"
page <- read_html(link)
我的输出和错误消息:
link <- "https://www.hepsiburada.com/lg-70nano756pa-70-177-ekran-uydu-alicili-4k-ultra-hd-smart-led-tv-p-HBCV00000YCM48"
> page <- read_html(link)
Error in open.connection(x, "rb") : HTTP error 403.
>
> price = page %>% html_nodes(".productPrice") %>% html_text()
Error in UseMethod("xml_find_all") :
no applicable method for 'xml_find_all' applied to an object of class "function"
> seller = page %>% html_nodes(".merchantName") %>% html_text()
Error in UseMethod("xml_find_all") :
no applicable method for 'xml_find_all' applied to an object of class "function"
price = page %>% html_nodes(".productPrice") %>% html_text()
seller = page %>% html_nodes(".merchantName") %>% html_text()
发布于 2022-06-30 11:10:37
如果httr2
和rvest
失败了,您可以始终依靠RSelenium
进行and操作。这里是一个例子,在这里我刮的标题和产品的价格。
library(tidyverse)
library(rvest)
library(RSelenium)
library(netstat)
rD <- rsDriver(browser = "firefox", port = free_port())
remDr <- rD[["client"]]
remDr$navigate(
"https://www.hepsiburada.com/lg-70nano756pa-70-177-ekran-uydu-alicili-4k-ultra-hd-smart-led-tv-p-HBCV00000YCM48"
)
html <- remDr$getPageSource()[[1]] %>%
read_html
tibble(
price = html %>%
html_element("#offering-price span") %>%
html_text2(),
title = html %>%
html_element("#product-name") %>%
html_text2()
)
# A tibble: 1 x 2
price title
<chr> <chr>
1 17.941 "LG 70NANO756PA 70\" 177 Ekran Uydu Alicili 4K Ultra HD Smart~
https://stackoverflow.com/questions/72811865
复制相似问题