2016-09-23 27 views
1

我正試圖在Capital Bikeshare網站上查看我的行程歷史數據。我必須登錄並進入旅行菜單查看數據。但我得到這個錯誤:Web Scrapping Capital Bikeshare個人行程歷史數據R

> `No encoding supplied: defaulting to UTF-8. 
Error in (function (classes, fdef, mtable) : 
    unable to find an inherited method for function ‘readHTMLTable’ for signature ‘"xml_document"’ 

這是我的代碼。

> library(httr) 
> library(XML) 
> handle <- handle("https://www.capitalbikeshare.com/") 
> path <-"profile/trips" 

> login <- list(profile_login="myemail", profile_pass ="mypassword", profile_redirect_url="https://secure.capitalbikeshare.com/profile/trips/QNURCMF2Q6") 
> response <- POST(handle = handle, path = path, body = login) 
> readHTMLTable(content(response)) 

我也使用rvest嘗試,但後來我一直得到「Error: Unknown field names: _username, _password」的錯誤。我應該在這裏使用哪個字段?我嘗試了ID,姓名等,但仍然無法使用。

回答

2

對於啓動會員登錄網頁是比你上面列出的介紹頁面不同:

這可能不是正確的,但試圖以此爲可能rvest起點:

login<-"https://secure.capitalbikeshare.com/profile/login" 

library(rvest) 
pgsession<-html_session(login) 
pgform<-html_form(pgsession)[[1]] 
#update user id and password in the next line 
filled_form<-set_values(pgform, "_username"="[email protected]", "_password"="password") 
submit_form(pgsession, filled_form) 

一旦你再登錄一個可以使用jump_to功能移動到所需的網頁:

page<-jump_to(pgsession, newurl) #newurl will be the address where to go to next. 

希望這會有所幫助,如果不工作,發表評論,我會DELE這個職位。

+0

我得到這個錯誤錯誤xml2 :: url_absolute(url,x $ url):object'newurl'not found' after page <-jump_to(pgsession,newurl)' – jso1226

+0

@ jso1226,如果你有這麼遠登錄步驟奏效。對不起,我應該更清楚了,「newurl」將成爲你希望去的頁面的網址。當我完成類似的步驟時,我必須在代碼中預先定義此URL。 – Dave2e

+0

我不再有錯誤,它似乎是通過了,但我需要運行另一個命令?我想看看它是否會給我我應該看到的領域,如旅行信息和持續時間。所以我運行'摘要(頁面)',但它給了我一個句柄,配置,網址,後退,轉發,響應和HTML行長度,類和模式列作爲表。 – jso1226