python_爬虫爬取库房无忧网的库房数量

原创不易,转发请带本文链接
爬虫爬取库房无忧网每个城市的库房数量
爬取前请到高德地图找到自己城市的起始经纬度和终止经纬度

import os

import requests
from utils.read_write import writeOneCSV, writeOneJSON, readJson

'''
    此文件用于抓取库房无忧网的库房数据
'''
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko)'
                  ' Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'}
os.chdir(r'D:\project\jianguiyuan\\')

def count(district, houseType):
    url = 'http://sz.kufangwuyou.com/house/count'
    data = {
        "level": 3,
        "houseType": "5",
        "city": "440300",
        "start": 0,
        "pageSize": 1000,
        "longitudeStart": 113.33913,
        "latitudeStart": 22.046212,
        "longitudeEnd": 114.83276,
        "latitudeEnd": 23.045959
    }
    r = requests.post(url, headers=headers, json=data)
    response = r.json()
    if response['result']['data']:
        file = str(houseType) + '_' + str(district) + '_' + '.json'
        writeOneJSON(response['result'], json_dir + file )


if __name__ == "__main__":
    json_dir = 'D:\data\深圳政府数据\深圳库房数据\count\json\level3\\'
    child_json = 'data\\child.json'
    child = readJson(child_json)
    result = child['result']
    for houseType in [1, 2, 5]:
        for one in result:
            district = one['areaId']
            # street = one['child']['areaId']
            count(district, houseType)

如需帮忙抓取数据,请私聊我,我这暂时只有深圳的

发布了16 篇原创文章 · 获赞 9 · 访问量 7131

猜你喜欢

转载自blog.csdn.net/qq_30803353/article/details/105547524