爬取高德地图路况信息,全国主要城市拥堵前10名的商圈和路段

全国主要城市拥堵前10名的商圈和路段爬虫,每5分钟跟新一次

具体代码欢迎查看我的github小小项目https://github.com/xiaofei6677/Crawl-Amap-road

主要利用的网址是http://report.amap.com/index.do

通过http://report.amap.com/detail.do?city=110000

可以看到北京的城市代码是110000

通过点击其他城市可以查看其他城市代码

道路拥堵代码

import pandas as pd
import requests
import time
while True:
    t = time.strftime("%H%M%S", time.localtime())
    r =requests.get("http://report.amap.com/ajax/roadRank.do?roadType=0&timeType=0&cityCode=110000")#可以换成其他城市代码
    s=r.json()
    a=[]
    for i in range(len(s["tableData"])):
        for j in range(len(s["tableData"][i]["coords"])):
            a.append([s["tableData"][i]["coords"][j]["lon"],s["tableData"][i]["coords"][j]["lat"],s["tableData"][i]['name'],s["tableData"][i]['index'],s["tableData"][i]['speed']])
    c = pd.DataFrame(a)
    c.to_csv(t+'road.csv')
    time.sleep(300)

商圈爬虫代码

import pandas as pd
import time
import requests
while True:
    t = time.strftime("%H%M%S", time.localtime())
    r =requests.get("http://report.amap.com/ajax/districtRank.do?linksType=3&cityCode=110000")#可以换成其他城市代码
    s=r.json()
    a=[]
    for i in range(len(s)):
        for j in range(len(s[i]['coords'][0][0])):
            a.append([s[i]['coords'][0][0][j]['lon'],s[i]['coords'][0][0][j]['lat'],s[i]['name'],s[i]['index'],s[i]['speed'],s[i]['number']])
    c = pd.DataFrame(a)
    c.to_csv(t+'new.csv')
    time.sleep(300)

猜你喜欢

转载自blog.csdn.net/qq_912917507/article/details/81085535