说明
1、获取网站:税法查询 (chinatax.gov.cn)
2、使用框架:💥 3.2 功能介绍 - DrissionPage (gitee.io) 3.2版本
3、存储介质: Sqlite 数据库
图片展示:
以下部分核心代码:
[Python] 纯文本查看 复制代码 # 获取税法列表
def getTaxList(session, typecode, conn):
# 根据类型获取明细数据
url = "https://12366.chinatax.gov.cn/sscx/search?page=1&pageSize=4&zltype=" + typecode + "&zlflag=1&keywords=&order=desc&sortField=ZLBFRQ"
res = session.get(url)
if res.status_code == 200:
taxList = res.json() # 税法列表
pageCount = taxList["pageCount"]
print(typecode + " 共有 " + str(taxList["totalRow"]) + " 条")
for px in range(1, pageCount + 1):
getPageContent(session, typecode, px, conn)
else:
print(" 获取数据异常!")
# 获取单条税法内容
def getPageContent(session, typecode, pageix, conn):
res = session.get("https://12366.chinatax.gov.cn/sscx/search?page=" + str(
pageix) + "&pageSize=4&zltype=" + typecode + "&zlflag=1&keywords=&order=desc&sortField=ZLBFRQ")
try:
if res.status_code == 200:
taxList = res.json() # 税法列表
pageContent = taxList["pageContent"]
c = conn.cursor()
for row in pageContent:
ZLCODE = row["ZLCODE"] # 税法代码
ZLBFRQ = row["ZLBFRQ"] # 颁发日期
ZLFBRQ = row["ZLFBRQ"] # 发布日期
TITLE = row["TITLE"] # 税法标题
ZLNR = row["ZLNR"] # 税法内容
ZLGJZ = row["ZLGJZ"] # 类别
ZLWH = row["ZLWH"] # 税法文号
c.execute("insert into taxList(fcode,ffbrq,fbfrq,ftitle,fnr,fgjz,fwh) values(?,?,?,?,?,?,?)",
(ZLCODE, ZLFBRQ, ZLBFRQ, TITLE, ZLNR, ZLGJZ, ZLWH))
conn.commit()
c.close()
except Exception as e:
conn.rollback()
print("ERROR: " + str(e))
附件地址:
taxlaw.zip
(790.07 KB, 下载次数: 54)
|