代码如下:
import io
import requests
def download_pdf(save_path,pdf_name,pdf_url):
send_headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36",
"Connection": "keep-alive",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
"Accept-Language": "zh-CN,zh;q=0.8"}
response = requests.get(pdf_url, headers=send_headers)
bytes_io = io.BytesIO(response.content)
with open(f'{pdf_name}.pdf', mode='wb') as f:
f.write(bytes_io.getvalue())
print(f'{pdf_name}.PDF,下载成功!')
if __name__ == '__main__':
save_path = 'E:\Code\python\python学习'
pdf_name='2007年年度报告'
pdf_url="http://static.cninfo.com.cn/finalpage/2008-03-27/38334292.PDF"
download_pdf(save_path, pdf_name, pdf_url)
标签:__,name,python,demo,url,io,pdf,下载
From: https://www.cnblogs.com/code3/p/17368430.html