爬虫腾讯地图-5WNBZ-2JYR6-SPUSL-M3WGH-U4KDT-K2FYV

#!coding=utf-8
import requests
import re
import random
import time
import json
# from requests.packages.urllib3.exceptions import InsecureRequestWarning
import pandas as pd

# requests.packages.urllib3.disable_warnings(InsecureRequestWarning)  ###禁止提醒SSL警告

key = ''  ##开发者密钥ID


class dzdp(object):

    def __init__(self, keyword):
        self.keyword = keyword
        self.citylist = [
           '安次区','广阳区','永清县','文安县','大城县','大厂回族自治县','香河县','固安县'
        ]

    ##城市内搜索结果
    def search_qqmap(self):
        df = pd.DataFrame(columns=('ID', '店名', '地址', '电话', '类别', '纬度', '经度', '邮编', '省', '市', '区'))
        x = 0
        for i in self.citylist:
            # p = 1
            for p in range(1,11):
                time.sleep(0.22)
                url = 'https://apis.map.qq.com/ws/place/v1/search?boundary=region({},0)&page_size=20&page_index={}&keyword={}&orderby=_distance&key={}'.format(
                    i, p, self.keyword, key)
                req = requests.get(url=url, verify=False).json()
                print(req)
                data = req['data']

                if data != []:
                    for j in data:
                        id = j['id']  ##ID
                        title = j['title']  ##店名
                        address = j['address']  ##地址
                        tel = j['tel']  ##电话
                        category = j['category']  ##类别
                        lat = j['location']['lat']  ##纬度
                        lng = j['location']['lng']  ##经度
                        adcode = j['ad_info']['adcode']  ##邮编
                        province = j['ad_info']['province']  ##省
                        city = j['ad_info']['city']  ##市
                        district = j['ad_info']['district']  ##区
                        print(id, title, address, tel, category, lat, lng, adcode, province, city, district)
                        df.loc[x] = [id, title, address, tel, category, lat, lng, adcode, province, city, district]
                        x = x + 1



        df.to_excel(self.keyword + '.xlsx', index=False, encoding="GB18030")


if __name__ == '__main__':
    keywords = ['汽车保养','汽车美容','汽车维修','汽车装饰',]
    for keyword in keywords:
        dp = dzdp(keyword)
        dp.search_qqmap()


'''https://apis.map.qq.com/ws/place/v1/search?boundary=region(廊坊,0)&page_size=20&page_index=100&keyword=汽车维修&orderby=_distance&key=5WNBZ-2JYR6-SPUSL-M3WGH-U4KDT-K2FYV'''
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值