问题遇到的现象和发生背景
Python 网站爬虫
请问怎样在以下网站中自动爬取规定日期范围内【发行结果】版块下面 的带有"发行结果,发行情况" 关键字的公告文件,并将文件名称以超链接的格式复制粘贴到excel中 (并在excel中包含自动去重功能)? 感谢
网站链接:https://www.chinabond.com.cn/Channel/21000
Python 网站爬虫
请问怎样在以下网站中自动爬取规定日期范围内【发行结果】版块下面 的带有"发行结果,发行情况" 关键字的公告文件,并将文件名称以超链接的格式复制粘贴到excel中 (并在excel中包含自动去重功能)? 感谢
网站链接:https://www.chinabond.com.cn/Channel/21000
import requests
#获取网站的 HTML 内容
url = "https://www.chinabond.com.cn/Channel/21000"
response = requests.get(url)
html = response.text
#使用 Beautiful Soup 解析 HTML 内容
from bs4 import BeautifulSoup
soup = BeautifulSoup(html, "html.parser")
links = soup.find_all("a", string=re.compile("发行结果|发行情况"))
#保存
from openpyxl import Workbook
workbook = Workbook()
sheet = workbook.active
# 在第 1 列中插入文件名称
for i, link in enumerate(links):
sheet.cell(row=i+1, column=1).value = link.text
sheet.cell(row=i+1, column=1).hyperlink = link["href"]
workbook.save(地址)