1 Star 0 Fork 0

brianben/wwwroot

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
KBleads_CJ.py 7.09 KB
一键复制 编辑 原始数据 按行查看 历史
brianben 提交于 2022-04-23 10:40 . Changes
# 口碑leads分类目采集
# https://kbservcenter.alipay.com/sale/leads/queryPublicCondition.json?pageSize=40&current=3&name=&leadsId=&companyName=&categoryId=2015062600004525&brand=&labels=&provinceCode=360000&cityCode=360100&districtCode=360102&_ts=1650422942794&pageNum=3&_input_charset=utf-8&ctoken=iEDBl7RoxdWICXBc
'''
东湖区:
districtCode 360102
安义县:
districtCode 360123
红谷滩区:
districtCode 360113
进贤县:
districtCode 360124
南昌县:
districtCode 360121
青云谱:
districtCode 360104
青山湖区:
districtCode 360111
西湖区:
districtCode 360103
新建区:
districtCode 360112
{"360102":'东湖区','360123':'安义县','360113':'红谷滩区','360124':'进贤县','360121':'南昌县','360104':'青云谱','360111':'青山湖区','360103':'西湖区','360112':'新建区'}
休闲娱乐:
categoryId 2015062600004525
医疗健康:
categoryId 2016062900190296
美发美容美甲:
categoryId 2015063000013612
运动健身:
categoryId 2015110500071135
亲子:
categoryId 2016012900142587
爱车服务:
categoryId 2019030100288365
便民服务:
categoryId 2020111900333639
洗衣:
categoryId 2016051000170051
K歌:
categoryId 2016042200000078
医疗健康服务:
categoryId 2019022600282348
摄影:
categoryId 2016042200000048
美食:
categoryId 2015050700000000
教育技能培训:
categoryId 2017070600257594
家庭服务:
categoryId 2020063000323540
宠物:
categoryId 2016012900147216
结婚:
categoryId 2016012900133526
'''
import requests, csv, time
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
dic={"360102":'东湖区','360123':'安义县','360113':'红谷滩区','360124':'进贤县','360121':'南昌县','360104':'青云谱','360111':'青山湖区','360103':'西湖区','360112':'新建区'}
KB_header = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.44'
headers = {
'User-Agent': KB_header,
'X-Requested-With': 'XMLHttpRequest',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'Accept-Encoding': 'gzip, deflate, br',
'Accept': 'application/json, text/javascript',
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',
'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="100", "Microsoft Edge";v="100"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'Referer': 'https://kbservcenter.alipay.com/sale/index.htm',
}
cooies = {'JSESSIONID': '3336BDD42162AB37F39AC22729B64F86', ' cna': 'tnxyGSKemmECAbfZGjOMVJLc',
' buservice_domain_id': 'KOUBEI_SALESCRM', ' sdvt': 'uJ8lFkKSwhu8LfGmK6E9brTNoAnxRQDp',
' mobileSendTime': '-1', ' credibleMobileSendTime': '-1', ' ctuMobileSendTime': '-1',
' riskMobileBankSendTime': '-1', ' riskMobileAccoutSendTime': '-1', ' riskMobileCreditSendTime': '-1',
' riskCredibleMobileSendTime': '-1', ' riskOriginalAccountMobileSendTime': '-1', ' IS_INNER_LOGIN': '0',
' ALIPAYCHAIRBUCJSESSIONID': '92dbbd52-2fea-47fa-a931-d7c7ffd53b0e',
' spanner': 'RguqVXs6BjGSnxmzyEBk22brduy9e+Vq', ' sso.global.authtoken': 'sso.global.authtoken',
' session.cookieNameId': 'ALIPAYBUMNGJSESSIONID',
' isg': 'BNHRT-tLV78sorjt8794-pB24N1rPkWwla7d1rN7rhslWjqsvIudgGH7-C68193o',
' l': 'eBTXpL9ngNi2rH4GB91Qnurza7795FOXtyygaNbMiIErmO1h8BPvBsVWOouB8V6w2wwlHsjP73loI7mWB4YyWyCSnxv9-x0I5VkSndC..',
' tfstk': 'c-TdBJ1TaADnlR19gHnMa1zTgwYFaiFdEW68yUQLgRYaZPFbMsbMoE3jbD1P39hO.', ' kbUserType': 'PROVIDER',
' uvUserId': '2088341981266556', ' JSESSIONID': '3336BDD42162AB37F39AC22729B64F86',
' ALIPAYBUMNGJSESSIONID': 'GZ008hJWehajfBURH6tFXC9jl2gdvtkbservcenterGZ00',
' ALIPAYJSESSIONID': 'RZ55KnRh5LVcFjhD4eVo5xkJQsOu4TauthRZ55', ' ctoken': 'i5cEjS9aqHgy_iCW',
' auth_goto_http_type': 'https', ' _l_n': '2088341981266556',
' rtk': 'aZtc6popvtokLahc5yhqBfpeS9sAxnMQ0E8grm8p1Zidxn4T1tU', ' zone': 'GZ00G'}
jh_s = requests.Session()
district = [360102, 360123, 360113, 360124, 360121, 360104, 360111, 360103, 360112]
category = [2015062600004525, 2016062900190296, 2015063000013612, 2015110500071135, 2016012900142587, 2019030100288365,
2020111900333639, 2016051000170051
, 2016042200000078, 2019022600282348, 2016042200000048, 2015050700000000, 2017070600257594, 2020063000323540,
2016012900147216, 2016012900133526]
page = 1
shopLeadses = 'x'
for districtCode in district:
page = 1
for categoryId in category: # 每次循环开始需要重置循环条件。
shopLeadses = 'x'
page = 1
while shopLeadses:
time.sleep(0.5)
url = 'https://kbservcenter.alipay.com/sale/leads/queryPublicCondition.json?pageSize=40' \
'&current={page}&name=&leadsId=&companyName=&categoryId={categoryId}&brand=&labels=' \
'&provinceCode=360000&cityCode=360105&districtCode={districtCode}&_ts=1650461629759&pageNum={page}' \
'&_input_charset=utf-8&ctoken=i5cEjS9aqHgy_iCW'.format(page=page, categoryId=categoryId,
districtCode=districtCode)
print('当前采集区域:', districtCode, '当前采集类目:', categoryId, '采集页数:', page)
res = jh_s.get(url=url, cookies=cooies, headers=headers, verify=False)
print('响应状态:', res)
try: # 说明没有获取到数据有可能是到了最后一页。
shopLeadses = res.json()['data']['queryResult']['shopLeadses']
except:
print('获取数据失败:', url)
page = 1
break
page = page + 1
if shopLeadses:
# print('shopLeadses:',shopLeadses)
for shop in shopLeadses:
info = []
shop_name = shop['name']
shop_leads = "~" + str(shop['leadsId'])
quyu = shop['address']
wangge_name = shop['areaName']
pinlei = shop['categoryName']
phone = "~" + str(shop['contactsPhone'])
# print(phone)
phone_name = shop['contactsName']
xx = "~" + str(districtCode)
info.append(shop_name)
info.append(shop_leads)
info.append(quyu)
info.append(wangge_name)
info.append(pinlei)
info.append(phone)
info.append(phone_name)
info.append(xx)
info.append('\n')
# print("待写入数据:",info)
with open('KB1235678.csv', 'a+', encoding='utf-8-sig', newline='') as csvfile:
# csvfile.writelines(info)
writer = csv.writer(csvfile)
writer.writerow(info)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/brianben/wwwroot.git
[email protected]:brianben/wwwroot.git
brianben
wwwroot
wwwroot
master

搜索帮助