0
我有很多地址需要進行地理編碼(查找經度和緯度)。美國人口普查局在以下鏈接提供這樣的服務:US Census Geocoder,每個請求限制在1000個地址。現在我必須一遍又一遍地手動完成。我正在學習Python,我很想知道如何自動完成它。我應該使用哪些軟件包以及如何指定一個輸入文件,該文件在網站上要求我點擊「選擇文件」按鈕,然後選擇一個文件?使用文件輸入形式的Python POST Web請求
正如你所看到的,不會有太多的領域,以填補。表格描述爲:
<form method="POST" action="addressbatch" enctype="multipart/form-data">
<label>Select Address File :</label>
<input type="file", name="addressFile", required="required">
...
<div id="_f_gov_census_geo_geocoder_domain_AddressResult_benchmark_id">...</div>
...
<input type="submit" value="Get Results">
</form>
我已經看過請求包並試了一下。以下是我已經能夠做到:
url = 'http://geocoding.geo.census.gov/geocoder/locations/addressbatch?form'
payload = {'name': 'addressFile', 'filename':'C:/ds/data/california/census_geocode/batch_0.csv'}
session = requests.session()
r = requests.post(url, data=payload)
結果是r=<Response [400]
,或錯誤的請求。我不知道如何指定提交請求,因爲源只有類型和值字段,沒有名稱字段。
二手谷歌開發者工具來跟蹤的要求,這裏是我的了:
Request Payload:
------WebKitFormBoundaryINe95Tc7sF0LHtgj
Content-Disposition: form-data; name="addressFile"; filename="batch_0.csv"
Content-Type: application/vnd.ms-excel
------WebKitFormBoundaryINe95Tc7sF0LHtgj
Content-Disposition: form-data; name="benchmark"
4
------WebKitFormBoundaryINe95Tc7sF0LHtgj--
我仍然不知道如何在我的要求下,雖然使用這些信息。
我已經更新了我的問題,並展示了迄今爲止我所能找到的內容。顯然它還沒有解決。 – breezymri