You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blgj/getdata.py

52 lines
1.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*-coding:UTF-8-*-
'''根据行政区域查询'''
import json
import csv
import sys
import requests # 导入requests库这是一个第三方库把网页上的内容爬下来用的
ty = sys.getfilesystemencoding()
import time
las = 1 # 给las一个值1
ak = '您申请的KEY码'
out = open('j_str.csv', 'a', newline='')
csv_write = csv.writer(out, dialect='excel')
print(time.time())
print('开始')
urls = [] # 声明一个数组列表
que = '' \
'避险场所'
ta = '露天停车场'
for i in range(0, 20):
page_num = str(i)
url = 'https://mp.weixin.qq.com/s/K0u_qPFQtWuH4hk5K2xWfQ' + que + '&' \
'tag=' + ta + '&region=郑州&page_size=20&page_num=' + str(
page_num) + '&output=json&ak=' + ak
urls.append(url)
print('url列表读取完成')
for url in urls:
time.sleep(5) # 为了防止并发量报警设置了一个5秒的休眠。
print(url)
html = requests.get(url) # 获取网页信息
data = html.json() # 获取网页信息的json格式数据
print(data)
for item in data['results']:
jname1 = item['province']
jname2 = item['city']
jname3 = item['area']
jname4 = item['name']
jname = jname1 + jname2 + jname3 + jname4
j_uid = item['uid']
jstreet_id = item.get('street_id')
jlat = item['location']['lat']
jlon = item['location']['lng']
jaddress = item['address']
jphone = item.get('telephone')
j_str = (jname, j_uid, jstreet_id, str(jlat), str(jlon), jaddress, jphone)
print(j_str)
csv_write.writerow(j_str)
print("write over")
print(time.time())
print('完成')