You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

R语言爬虫抓取页面嵌入链接时报SSL证书过期错误如何解决

问题解决方法

核心原因

rvest::read_html()直接传入URL发起请求时,底层使用xml2内置的请求逻辑,不会复用你为httr配置的ssl_verifypeer = FALSE规则,仍然会执行完整SSL证书校验,因此子链接请求触发证书过期报错。

修复代码

你只需要将子链接的请求逻辑也统一使用带SSL配置的httr::GET发起,再将返回结果传入read_html即可,修改后的代码如下:

library(rvest)
library(httr)
library(magrittr)

webpage <- "https://fsncapital.com/en/investments/investments-divestments/"
page <- webpage %>% 
  httr::GET(config = httr::config(ssl_verifypeer = FALSE)) %>% 
  read_html()

## 提取内嵌的子链接
Comp_Links = page %>% html_nodes(".investments-grid .name") %>%
  html_attr("href")

## 获取公司所有权信息
get_ownership =function(comp_link) {
  # 子链接也使用带SSL配置的httr请求
  comp_raw <- httr::GET(comp_link, config = httr::config(ssl_verifypeer = FALSE))
  comp_page = read_html(comp_raw)
  ownership = comp_page %>% html_node("p:nth-child(4)") %>%
    html_text()
  return(ownership)
}

Ownership = sapply(Comp_Links, FUN = get_ownership)

补充说明

  • 跳过SSL证书校验存在安全风险,该操作仅建议用于你明确信任的目标站点。
  • 若修改后仍触发SSL报错,可在httr::config中额外添加ssl_verifyhost = FALSE配置,关闭主机名校验逻辑。

内容的提问来源于stack exchange,提问作者Philip Olsson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 04:06:04