问题
If you visit https://www.aucklandcouncil.govt.nz/property-rates-valuations/pages/find-property-rates-valuation.aspx then you will see search box.
I want '905/8 Ronayne St' to be input, and '12343197398' to be output.
I am using R and tried like this but didn't work..
post <- POST("https://www.aucklandcouncil.govt.nz/_vti_bin/ACWeb/ACservices.svc/GetMatchingPropertyAddresses",
body = list('ResultCount' = "10", 'SearchText' = "905/8 Ronayne St", 'RateKeyRequired' = "false"))
content(post, "text")
Can you please help me? That would be much appreciated :)
回答1:
Just need to provide the right header in R due to way sending.
R:
library(httr)
headers = c('Content-Type' = 'application/json; charset=UTF-8')
data = '{"ResultCount":"10","SearchText":"905/8 Ronayne St","RateKeyRequired":"false"}'
r <- httr::POST(url = 'https://www.aucklandcouncil.govt.nz/_vti_bin/ACWeb/ACservices.svc/GetMatchingPropertyAddresses', httr::add_headers(.headers=headers), body = data)
print(content(r)[[1]]$ACRateAccountKey)
Py:
import requests
data = {"ResultCount":"10","SearchText":"905/8 Ronayne St","RateKeyRequired":"false"}
r = requests.post('https://www.aucklandcouncil.govt.nz/_vti_bin/ACWeb/ACservices.svc/GetMatchingPropertyAddresses', json=data).json()
print(r[0]['ACRateAccountKey'])
来源:https://stackoverflow.com/questions/58655930/how-to-retrieve-response-by-using-post-in-r