python爬虫实战-获取部门预算文件公开时间

python爬虫实战-获取预算文件公开时间

#-*- codeing=UTF-8 -*-
#@Time : 2020/9/18 21:29
#@Author :syoopy
#@File : .py
#@Software : PyCharm

import requests
import json
import pandas as pd


headers = {"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"}

pid=160
starnum=0

#获取各部门
def getDepartment(pid,starnum):
    url = "http://yjsgk.jsczt.cn/front/department/getdepartmentname.do?pid="+str(pid)
    res = requests.get(url=url, headers=headers)
    res = res.content
    json_res = json.loads(res)
    for i in range(len(json_res)):
        if i < starnum:
            continue
        data = json_res[i]
        iid = data["iid"]
        getBudgetFinal(iid)

dict1 ={
    '标题':[],
    '预算公开时间':[]
}

def getBudgetFinal(iid):
    url = "http://yjsgk.jsczt.cn/front/budgetfinal/itemsandpag.do?page_num=1&groupid="+str(iid)+"&typeid=2"
    res = requests.get(url=url,headers=headers)
    res = res.content
    json_res = json.loads(res)
    i = 0
    for data in json_res["budgetTemplates"]:
        b_title = data["b_title"]
        realTime = data["realTime"]
        dict1['标题'].append(b_title)
        dict1['预算公开时间'].append(realTime)
        if i == 1:
            break
        i = i + 1
    write_to_excel()

def write_to_excel():
    df = pd.DataFrame(dict1)
    df.to_excel('./预算公开文件时间.xlsx',index=False)

if __name__ == '__main__':
    getDepartment(pid,starnum)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值