2013-01-14 66 views
4

在B週期頁面(www.bcycle.com/whowantsitmore.aspx)我試圖刮取票數的位置和值。使用R SOAP(SSOAP)檢索數據/刮

URL http://mapservices.bcycle.com/bcycleservice.asmx是一個SOAP服務。

基於documentation我相信我正確地做了,但由於解析輸入參數,我得到一個錯誤。即使調用沒有參數的函數也會產生錯誤。

# working with SOAP 
#install.packages("SSOAP", repos="http://www.omegahat.org/R", dependencies = T, type = "source") 
library(SSOAP) 

# Process the Web Service Definition Language (WSDL) file 
bcycle.asmx <- processWSDL("http://mapservices.bcycle.com/bcycleservice.asmx?WSDL") 

# Generate functions based on definitions to access the different data sets 
bcycle.interface <- genSOAPClientInterface([email protected][[1]], def = bcycle.asmx, [email protected], verbose=T) 

# Get the data by requesting the number of cities, username and password (yes it is public) 
[email protected]$getCities("10","bcycle","[email protected]") 
# receive error: Error in as(parameters, "limit.userName.pw") : 
# no method or default for coercing "character" to "limit.userName.pw" 

這是由於在功能如下代碼:

function(parameters = list(...),... etc) { 
    ... 
    as(parameters, "limit.userName.pw") 
    ... 
} 

因此我試圖用直接.soap擴展功能:

# Using RCurl library 
library(RCurl) 

# set up curl options 
curl.opts <- curlOptions(
    verbose=T, 
    header=T, 
    cookie="ASP.NET_SessionId=dv25ws551nquoezqwq3iu545;__utma=27517231.373920809.1357910914.1357910914.1357912862.2;__utmc=27517231;__utmz=27517231.1357910914.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none);__utmb=27517231.13.10.1357912862", 
    httpheader = c('Content-Type' = 'text/xml; charset=utf-8', Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"), 
    followLocation = TRUE, 
    useragent = "Mozilla/5.0 (Windows NT 6.1; rv:18.0) Gecko/20100101 Firefox/18.0") 

# Define header and submit request 
bcycle.server <- SOAPServer("http://mapservices.bcycle.com/bcycleservice.asmx") 
.SOAP(bcycle.server, 
    "getCities", 
    limit=250,userName="bCycle",pw="[email protected]", 
    action="http://bcycle.com/getCities", 
    xmlns="http://bcycle.com/", 
    .opts=curl.opts, 
    .literal=T, 
    nameSpaces = "1.2", 
    elementFormQualified = T, 
    .returnNodeName = 'getCitiesResponse', 
    .soapHeader = NULL) 

我管理連接到他們的服務器但收到錯誤:

System.Web.Services.Protocols.SoapException: 
    Server did not recognize the value of HTTP Header SOAPAction: 
    http://bcycle.com/getCities#getCities 

這些是我嘗試過的沒有成功的選項。

使用Python我能夠提出getCities請求,但沒有收到任何迴應。

​​3210

我在保持該R集中,但使用Python可以提供更容易洞察問題可能是真正感興趣。

任何想法?

+0

的http://mapservices.bcycle.com/bcycleservice.asmx?WSDL工作服務似乎不可用。 –

回答

1

嘗試糾正用戶名和明確命名參數:

library(SSOAP) 
bcycle.asmx <- processWSDL("http://mapservices.bcycle.com/bcycleservice.asmx?WSDL") 
bcycle.interface <- genSOAPClientInterface([email protected][[1]], 
           def = bcycle.asmx, [email protected], verbose=T) 
out <- [email protected]$getCities(
        limit="10",userName="bCycle",pw="[email protected]") 

#> out[[1]]@ 
#out[[1]]@zip    out[[1]]@state_name 
#out[[1]]@pop    out[[1]]@latitude 
#out[[1]]@ambassador_count out[[1]]@longitude 
#out[[1]]@city_name   

out[[1]]@city_name 
#[1] "toledo" 

Python的調用也將與該修正的用戶名

import suds 

client = suds.client.Client('http://mapservices.bcycle.com/bcycleservice.asmx?WSDL') 
client.service.getCities(10,'bCycle','[email protected]') 
(ArrayOfCities){ 
    Cities[] = 
     (Cities){ 
     zip = "43606" 
     pop = 337362 
     ambassador_count = 455261 
     city_name = "toledo" 
     state_name = "oh" 
     latitude = 41.6743 
     longitude = -83.6029 
     },............ 
+0

現貨。你明白了。令人驚訝的是使用正確的密碼有助於;)參數名稱是必需的,以及你的建議。謝謝! – Cyrille