首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我收到了HTTP错误403的网页抓取错误

我收到了HTTP错误403的网页抓取错误
EN

Stack Overflow用户
提问于 2022-06-30 07:29:12
回答 1查看 118关注 0票数 0

我试着上网刮擦。我有"HTTP错误403“错误。

代码语言:javascript
运行
复制
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)

我的输出和错误消息:

代码语言:javascript
运行
复制
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()
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-30 11:10:37

如果httr2rvest失败了,您可以始终依靠RSelenium进行and操作。这里是一个例子,在这里我刮的标题和产品的价格。

代码语言:javascript
运行
复制
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~
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72811865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档