这是一个通过自己接的爬取资产资质的单子,只用了30多行代码几分钟就轻松赚取到了2000块钱
下面是代码
# -*- coding: utf-8 -*-
# @Time : 2023-03-07 22:11
# @Author : Blue
# @File : main
import csv
from pathlib import Path
import requests
def get_list(page):
data = {
'params': '{"pagesize":20,"pagenum":%s,"unitorgnum":"","faren":"","zizhiname":"","qyren":"","zhuceziben":""}' % page
}
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
# 'Authorization': 'Bearer 8d9587cb442ea21ac8a7bb2a40fa1de8',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'https://www.jxsggzy.cn',
'Pragma': 'no-cache',
'Referer': 'https://www.jxsggzy.cn/ztxy/infor.html',
'Sec-Fetch-Dest': 'empty',
'Sec-Fetch-Mode': 'cors',
'Sec-Fetch-Site': 'same-origin',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
'X-Requested-With': 'XMLHttpRequest',
'sec-ch-ua': '"Chromium";v="110", "Not A(Brand";v="24", "Microsoft Edge";v="110"',
'sec-ch-ua-mobile': '?0',
'sec-ch-ua-platform': '"Windows"',
}
response = s.post('https://www.jxsggzy.cn/XZEWB-FRONT/rest/zhutiInformationAction/getDwInfo',
data=data, headers=headers)
result = response.json()
l = []
for item in result['ztinfo']:
areaname = item.get('areaname')
danweiguid = item['danweiguid']
danweiname = item.get('danweiname')
faren = item.get('faren')
unitorgnum = item.get('unitorgnum')
l.append((areaname, danweiguid, danweiname, faren, unitorgnum))
return l
def get_detail(danweiguid):
headers = {
'Accept': 'application/json, text/javascript, */*; q=0.01',
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
'CSRFCOOKIE': 'F85800B70085AF855EC01274CD7CB31C4E02C3E3',
'Cache-Control': 'no-cache',
'Connection': 'keep-alive',
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Origin': 'http://ggzyjy.jxsggzy.cn',
'Pragma': 'no-cache',
'Referer': f'http://ggzyjy.jxsggzy.cn/hygs/huiyuaninfo/pages/shigongzizhi/JtgcSgZiZhi_List?DanWeiType=132&DanWeiGuid={danweiguid}',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.63',
'X-Requested-With': 'XMLHttpRequest',
}
cookies = {
'_CSRFCOOKIE': 'F85800B70085AF855EC01274CD7CB31C4E02C3E3',
}
params = (
('cmd', 'page_Load'),
('DanWeiType', '132'),
('DanWeiGuid', danweiguid),
('isCommondto', 'true'),
)
data = {
'commonDto': '[{"id":"zizhicode","bind":"zizhicode","type":"treeselect-non-nested","action":"tree","idField":"id","textField":"text","imgField":"img","iconField":"iconCls","parentField":"pid","url":"jxpJtgcSgZiZhiListForWebAction.action?cmd=tree","valueField":"id","pinyinField":"tag","value":"","text":""},{"id":"zhengshuno","bind":"zhengshuno","type":"textbox","value":"","text":""},{"id":"datagrid","type":"datagrid","action":"defaultModel","idField":"rowguid","pageIndex":0,"pageSize":39,"sortField":"","sortOrder":"","columns":[{"fieldName":"zhengshuno"},{"fieldName":"zizhitype","code":"\u4EA4\u901A_\u8D44\u8D28\u79CD\u7C7B"},{"fieldName":"showzy"},{"fieldName":"deadlinedate","format":"yyyy-MM-dd"},{"fieldName":"btnscript"}],"url":"jxpJtgcSgZiZhiListForWebAction.action?cmd=defaultModel","data":[]},{"id":"_common_hidden_viewdata","type":"hidden","value":""}]'
}
response = s.post(
'http://ggzyjy.jxsggzy.cn/hygs/huiyuaninfo/pages/shigongzizhi/jxpJtgcSgZiZhiListForWebAction.action',
params=params, verify=False, data=data, cookies=cookies, headers=headers)
result = response.json()
l = []
for item in result['controls'][-2]['data']:
l.append((item['rownum_'], item['zhengshuno'], item['zizhitype'], item['showzy'], item['deadlinedate']))
return l
s = requests.session()
def run():
save_path = Path(__file__).parent.joinpath('结果')
save_path.mkdir(parents=True, exist_ok=True)
page = 1
while True:
result = get_list(page)
if not result:
break
for areaname, danweiguid, danweiname, faren, unitorgnum in result:
print(areaname, danweiguid, danweiname, faren, unitorgnum)
item_result = get_detail(danweiguid)
if item_result:
with open(save_path.joinpath(f'{danweiname}.csv'), 'w', encoding='utf-8', newline='') as f:
csv_write = csv.writer(f)
csv_write.writerow(['序号', '证书编号', '资质种类', '资质名称及等级', '截止时间'])
for item in item_result:
csv_write.writerow(item)
page += 1
if __name__ == '__main__':
run()
需要学习python兼职接单的可以加入我的星球里面有python教程