2017-03-06 9 views
0

このエラーがなぜ発生するのか分かりませんか?そのエラーがURLがHTTPSにリダイレクト意味...このニュースコンテンツを解析できません

site = "http://www.federalreserve.gov/feeds/prates.xml" 
doc <- tryCatch(xmlParse(site), error=function(e) e);  
Unknown IO errorfailed to load external entity  
"http://www.federalreserve.gov/feeds/prates.xml" 
src <- xpathApply(xmlRoot(doc), "//item") 
Error in UseMethod("xmlRoot") :no applicable method for 'xmlRoot'applied to an object of class "c('XMLParserErrorList', 'simpleError', 'error',  
'condition')" 
for (i in 1:length(src)) { 
if (i==1) { 
     foo<-xmlSApply(src[[i]], xmlValue) 
     temp<-data.frame(t(foo), stringsAsFactors=FALSE) 
     DATA=data.frame(title=temp$title,link=temp$link,description=temp$description,pubDate=temp$pubDate) 
    } 
    else { 
     foo<-xmlSApply(src[[i]], xmlValue) 
     temp<-data.frame(t(foo), stringsAsFactors=FALSE) 
     temp1=data.frame(title=temp$title,link=temp$link,description=temp$description,pubDate=temp$pubDate) 
     DATA<-rbind(DATA, temp1) 
    } 
} 
Error: object 'src' not found 
+0

XMLオブジェクトをURLではなく 'xmlParse'に渡す必要があります。 –

+0

そのサイトは現在https:// –

+0

です。@ chrisは関係ありません...私はXMLファイルを解析しています。 –

答えて

0

を私はタイトル、リンク、説明、日付& XMLPARSE関数を使用して、データフレームに保存のような形式でニュースコンテンツを解析しようとしていますが、それはのようなエラーがスローされます私のコメントで述べたように...

site   <- "http://www.federalreserve.gov/feeds/prates.xml" 
correct_site <- "https://www.federalreserve.gov/feeds/prates.xml" 

curlGetHeaders(site) 
[1] "HTTP/1.1 301 Moved Permanently\r\n"                           
[2] "Location: https://www.federalreserve.gov/feeds/prates.xml\r\n"                    
...  

xmlParse(site) 
Unknown IO errorfailed to load external entity "http://www.federalreserve.gov/feeds/prates.xml" 

xmlParseは、HTTPSから読み取るので、セキュアなHTTPからの読み取りにreadLines(警告を無視)またはxml2パッケージや他の多くのオプションを使用することはできません。

xmlParse(correct_site) 
Error: XML content does not seem to be XML: 'https://www.federalreserve.gov/feeds/prates.xml' 

x <- readLines(correct_site) 
Warning message: 
In readLines(correct_site) : 
    incomplete final line found on 'https://www.federalreserve.gov/feeds/prates.xml' 


xmlParse(x) 
<?xml version="1.0" encoding="utf-8"?> 
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd"> 
    <channel rdf:about="http://www.federalreserve.gov/feeds/"> 
    <title>FRB: DDP: Policy Rates</title> 
... 

library(xml2) 
read_xml(correct_site) 

{xml_document} 
<RDF schemaLocation="http://www.w3.org/1999/02/22-rdf-syntax-ns# rdf.xsd" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:cb="http://www.cbwiki.net/wiki/index.php/Specification_1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
[1] <channel rdf:about="http://www.federalreserve.gov/feeds/">\n <title>FRB: DDP: Policy Rates</title>\n ... 
[2] <item rdf:about="http://www.federalreserve.gov/feeds/PRATES.html#1765">\n <title>Change to the Publica ... 
[3] <item rdf:about="http://www.federalreserve.gov/feeds/PRATES.html#953">\n <title>Change to the Payment . 
+0

うわー!!それはクールなトリックreadLinesはhttpsで動作しますありがとうございます@Chris –

関連する問題