import requests import bs4 import Mysql import time import pymysql db = pymysql.connect(host="localhost",port=3306,user='root',password='Njx200259',db="sjz_kg") update = db.cursor() head = { "User-Agent":"""Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 Edg/114.0.1823.82""" } longitude = 114.397948 latitude = 38.08732 while longitude<114.664416 and latitude>37.778511: print('开始') url="https://ditu.amap.com/service/regeo?longitude="+str(longitude)+"&latitude="+str(latitude) print("\n"+url) params = { "longitude": str(str(longitude)), "latitude": str(str(latitude)) } r = requests.get(url,headers = head,params = params) r.encoding="utf-8" road_data=r.json()["data"]["road_list"] for road in road_data: name=road["name"] level=road["level"] print(name+" : "+level) print("UPDATE road set road_level = "+str(level)+" where road_name = '"+name+"'") update.execute("UPDATE road set road_level = "+str(level)+" where road_name = '"+name+"'") db.commit() longitude=longitude+0.001 if(longitude>114.664416): longitude=114.397948 latitude = latitude - 0.001
标签:name,level,python,地图,longitude,爬取,str,latitude,road From: https://www.cnblogs.com/cocotun/p/17571005.html