2014-02-15 96 views
0

我想使用R和rcurl包訪問網頁。 這裏是我的代碼:R Rcurl的結果與firefox不同

library(RCurl) library(XML)

URL <- "http://www.lfp.fr/ligue1/calendrier_resultat#sai=82&jour=1" 
siteHTML <- getURL(url=URL) 
xmltext <- htmlParse(siteHTML, asText=TRUE, encoding = 'UTF-8') 
Date_Match <- sapply(xpathSApply(xmltext, '//*[@id="tableaux_rencontres"]//h4'), xmlValue) 
Date_Match 

結果並不好...一樣,如果怨婦= 1參數不就不存在。 如果我嘗試使用Firefox訪問此頁面,那就OK了。

我也試試這個代碼沒有成功:

x <- getForm("http://www.lfp.fr/ligue1/calendrier_resultat", 
     jour="2", 
     sai="82") 
xmltext <- htmlParse(x, asText=TRUE, encoding = 'UTF-8') 
Date_Match <- sapply(xpathSApply(xmltext, '//*[@id="tableaux_rencontres"]//h4'), xmlValue) 
Date_Match 

你知道爲什麼嗎?解決辦法是什麼 ?你可以幫我嗎 ? 我是R編程的初學者,所以不要猶豫,給大的解釋。

回答

1

使用?,而不是#在網址:

library(RCurl) 
library(XML) 
URL <- "http://www.lfp.fr/ligue1/calendrier_resultat?sai=82&jour=1" 
siteHTML <- getURL(url=URL) 
xmltext <- htmlParse(siteHTML, asText=TRUE, encoding = 'UTF-8') 
Date_Match <- sapply(xpathSApply(xmltext, '//*[@id="tableaux_rencontres"]//h4'), xmlValue) 
Date_Match 
# [1] "Vendredi 14 février 2014" "Samedi 15 février 2014" "Dimanche 16 février 2014"