爬取平安银行所有网点的名称、所在城市、具体地址

import requests

from urllib.request import quote

from json import dumps

import openpyxl

wb=openpyxl.Workbook()

sheet=wb.active

sheet.title='平安银行网点分部表'

row=['网点名称','城市','具体地址']

sheet.append(row)

y=0

url='https://ebank.pingan.com.cn/rsb/bron/coss/cust/app/getBankShowCityListJsonp?callback=callback&type=YYWD&_=1564541370623'

headers={'user-agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36'}

list=[]

res=requests.get(url,headers=headers)

re=res.text[9:-2]

dic=eval(re)

datas=dic['data']

for i in range(len(datas)):

    city=datas[i]['city']

    list.append(city)

for m in list:

    y=y+1

    h=1564545962762+y

    gbk=m.encode('utf-8')

    url_1='https://ebank.pingan.com.cn/rsb/bron/coss/cust/app/getBankShowListJsonp?callback=callback&source=WEB&city='+quote(gbk)+'&type=YYWD&_='+str(h)

    ress=requests.get(url_1,headers=headers)

    respon=ress.text[9:-2]

    dics=eval(respon)

    lists=dics['data']

    for x in range (len(lists)):

        address=lists[x]['address']

        name=lists[x]['name']

        city=lists[x]['city']

        sheet.append([name,city,address])

wb.save('平安银行网点分部.xlsx')

你可能感兴趣的:(爬取平安银行所有网点的名称、所在城市、具体地址)