資源簡介
可以運行的高德地圖交通態(tài)勢爬取,代碼為爬取的大連市高新園區(qū)的交通態(tài)勢
代碼片段和文件信息
import?requests
import?pandas?as?pd
import?json
import?time
url?=?“https://restapi.amap.com/v3/traffic/status/rectangle?key=0488689d1ceeec1a994536d0953caf12&extensions=all&rectangle=“
baselng?=?121.513909
baselat?=?38.840823
widthlng?=?0.05
widthlat?=?0.04
x?=?[]
#?用于標識交通態(tài)勢線段
num?=?0
try:
????#?循環(huán)每個網(wǎng)格進行數(shù)據(jù)爬取
????for?i?in?range(0?6):
????????#?設(shè)定網(wǎng)格單元的左下與右上坐標的緯度值
????????#?在這里對數(shù)據(jù)進行處理,使之保留6位小數(shù)
????????startlat?=?round(baselat?+?i?*?widthlat?6)
????????endlat?=?round(startlat?+?widthlat?6)
????????for?j?in?range(0?6):
????????????#?設(shè)定網(wǎng)格單元的左下與右上坐標的經(jīng)度值
????????????startlng?=?round(baselng?+?j?*?widthlng?6)
????????????endlng?=?round(startlng?+?widthlng?6)
????????????#?設(shè)置API的URL并進行輸出測試
????????????locStr?=?str(startlng)?+?““
評論
共有 條評論