2017-07-19 6 views
0

私はRを使ってURL(http://www.foxnews.com/search-results/search?q= "AlphaGo" & ss = fn & start = 0)からニュースをクロールしたいと考えています。ここに私のコードは次のとおりです。ファイル内の"angular.callbacks"ウェブからのクロールデータ

エラー(CON、 "R"):接続

を開くことができませんが、エラーが現れたとして

url <- "http://api.foxnews.com/v1/content/search?q=%22AlphaGo%22&fields=date,description,title,url,image,type,taxonomy&section.path=fnc&start=0&callback=angular.callbacks._0&cb=2017719162" 
html <- str_c(readLines(url,encoding = "UTF-8"),collapse = "") 
content_fox <- RJSONIO:: fromJSON(html) 

しかし、JSONは理解することができませんでした

私は、jsonがangular.callbacks._0から始まることに気付きました。これは問題だと思います。

これを修正する方法はありますか?

答えて

0

Parse JSONP with Rで答えによると、私は2つの新しいものに自分のコードをajusted、それが働いた:

url <- "http://api.foxnews.com/v1/content/search?q=%22AlphaGo%22&fields=date,description,title,url,image,type,taxonomy&section.path=fnc&start=0&callback=angular.callbacks._0&cb=2017719162" 
html <- str_c(readLines(url,encoding = "UTF-8"),collapse = "") 
html <- sub('[^\\{]*', '', html) # remove function name and opening parenthesis 
html <- sub('\\)$', '', html) # remove closing parenthesis 
content_fox <- RJSONIO:: fromJSON(html) 
関連する問題