2017-08-14 64 views

回答

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)