求一份采用py3.7及以后版本的爬取国家法定节假日

查看 42|回复 2
作者:yihongceo   
求一份采用python3.7及以后版本的爬取国家法定节假日,并保存到oracle数据库,新手小白,没学过py,但是最近还需要这部分数据,求助

版本, 法定节假日

jamstory   

import requests
from bs4 import BeautifulSoup
import cx_Oracle
# 连接Oracle数据库
conn = cx_Oracle.connect('username/password@hostname:port/sid')
# 创建游标
cur = conn.cursor()
# 爬取国家法定节假日的网页
url = 'http://sousuo.gov.cn/s.htm?t=paper&advance=false&n=10&timetype=timeqb&mintime=0&maxtime=0&sort=pubtime&sortType=1&searchfield=&pcodeJiguan=&childtype=&subchildtype=&tsbq=&pubtimeyear=&puborg=&q=%E5%9B%BD%E5%AE%B6%E6%B3%95%E5%AE%9A%E8%8A%82%E5%81%87%E6%97%A5'
response = requests.get(url)
# 解析网页
soup = BeautifulSoup(response.content, 'html.parser')
table = soup.find('table', {'class': 'wtable'})
# 提取数据并保存到Oracle数据库
for tr in table.find_all('tr')[1:]:
    tds = tr.find_all('td')
    holiday_date = tds[1].get_text().strip()  # 节假日日期
    holiday_name = tds[2].get_text().strip()  # 节假日名称
    cur.execute("INSERT INTO HOLIDAYS(HOLIDAY_DATE, HOLIDAY_NAME) VALUES (:1, :2)", (holiday_date, holiday_name))
    conn.commit()
# 关闭游标和数据库连接
cur.close()
conn.close()
yihongceo
OP
  


jamstory 发表于 2023-3-8 15:40
import requests
from bs4 import BeautifulSoup
import cx_Oracle

爬不到
您需要登录后才可以回帖 登录 | 立即注册

返回顶部