【问题标题】:Error importing json data using google custom search and R使用谷歌自定义搜索和 R 导入 json 数据时出错
【发布时间】:2016-07-05 22:10:09
【问题描述】:

我正在使用带有 R 的谷歌自定义搜索。代码看起来像,

library(httr,lib.loc = "C:\\R packages")
URL<-"https://www.googleapis.com/customsearch/v1?"
key<-"key=xxxxxxxxxxxxxxxxxxxxxxxexxx"
cx<-"&cx=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
q<-"&q="
prod<-gsub(" ","+",prod)
URL<-paste0(URL,key,cx,q,prod)

当我将 URL 复制粘贴到浏览器中时,我能够获得 json 输出。不过,

 content(GET(URL))

给出以下错误,

Error in curl::curl_fetch_memory(url, handle = handle) : 
Problem with the SSL CA cert (path? access rights?)

任何输入都会很棒。谢谢。

【问题讨论】:

  • 如果URL返回JSON,也许试试library(jsonlite); fromJSON(url)
  • 成功了!谢谢大佬

标签: json r google-custom-search


【解决方案1】:

您可以使用library(jsonlite) 和函数fromJSON() 直接从url 读取JSON

library(jsonlite)
js <- fromJSON(url)

?fromJSON 给出的地方

fromJSON(txt,simplifyVector = TRUE,simplifyDataFrame = simpleVector, 简化矩阵 = 简化向量,展平 = FALSE,...)

txt - JSON 字符串、URL 或文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    • 1970-01-01
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多