用python写一段代码,实现找http://www.icbc.com.cn/ 上的一个公告附件下载。例如: https://www.icbc.com.cn/page/800009054201618432.html
时间: 2023-09-02 16:09:26 浏览: 44
好的,以下是一个简单的 Python 代码,可以从 ICBC 网站下载一个公告附件:
```python
import requests
url = "https://www.icbc.com.cn/page/800009054201618432.html"
response = requests.get(url)
if response.status_code == 200:
# 找到附件链接
start_index = response.text.find('<a href="/ICBCDynamicSite2/other/2018/20180823_2.html"')
end_index = response.text.find('</a>', start_index)
link = response.text[start_index:end_index]
link = link.replace('<a href="', '')
link = 'https://www.icbc.com.cn' + link
# 下载附件
response = requests.get(link)
with open('icbc_announcement.pdf', 'wb') as file:
file.write(response.content)
print('下载完成')
else:
print('无法连接到 ICBC 网站')
```
请注意,由于 ICBC 网站的结构可能会随时更改,以上代码可能需要进行适当的调整才能正常工作。此外,该代码可能违反 ICBC 的网站使用条款,请谨慎使用。