如何将数据从News River API提取到R

时间:2017-08-14 18:03:12

标签: r web-scraping httr news-feed jsonlite

尝试将数据从NewsRiver API提取到R.特别想将提供的json转换为数据帧以进行进一步分析。我还希望能够输入我自己的搜索词和域,我想从中搜索变量。

https://newsriver.io/

1 个答案:

答案 0 :(得分:1)

library(httr)
library(jsonlite)

set_config(config(ssl_verifypeer = 0L))

search_1 <- "Amazon"
search_2 <- "World Domination"
website <- "bloomberg.com"


url <- sprintf('https://api.newsriver.io/v2/search?query=text%%3A%s%%20OR%%20text%%3A%s%%20OR%%20website.domainName%%3A%s%%20OR%%20language%%3AEN&sortBy=_score&sortOrder=DESC&limit=100', search_1, search_2, website)
api_key <- "mykey"

news <- GET(url, add_headers(Authorization = paste(api_key, sep = "")))
news_txt <- content(news, as = "text")
news_china_df <- fromJSON(news_txt)