您的位置:首页 > 游戏 > 游戏 > 领英如何创建公司主页_erp信息管理系统_google adsense_安卓系统优化软件

领英如何创建公司主页_erp信息管理系统_google adsense_安卓系统优化软件

2025/3/1 5:42:34 来源:https://blog.csdn.net/weixin_63566653/article/details/145805791  浏览:    关键词:领英如何创建公司主页_erp信息管理系统_google adsense_安卓系统优化软件
领英如何创建公司主页_erp信息管理系统_google adsense_安卓系统优化软件

修改前的代码

但是总显示“失败”

原因是

修改之后的代码

import requests
import os
from urllib.parse import unquote# 原始URL
url = 'https://cn.bing.com/images/search?view=detailV2&ccid=TnImuvQ0&id=5AE65CE4BE05EE7A79A73EEFA37578E87AE19421&thid=OIP.TnImuvQ0eOu3Ncn8G7W4BQHaE8&mediaurl=https%3a%2f%2fpic.nximg.cn%2ffile%2f20230512%2f33688781_144207815103_2.jpg&exph=683&expw=1024&q=%e9%87%8d%e5%ba%86%e9%82%ae%e7%94%b5%e5%a4%a7%e5%ad%a6%e5%9b%be%e7%89%87%e5%ba%93&simid=608017321150603477&FORM=IRPRST&ck=82C8DD3330C84300350495177BFC73F6&selectedIndex=0&itb=0&idpp=overlayview&ajaxhist=0&ajaxserp=0'# 解析出实际的图片URL
media_url_encoded = url.split('mediaurl=')[-1].split('&')[0]
media_url = unquote(media_url_encoded)# 定义保存图片的目录和文件名
root = 'E://'
filename = media_url.split('/')[-1]
path = os.path.join(root, filename)try:# 确保目录存在if not os.path.exists(root):os.makedirs(root)# 如果文件不存在,则下载图片if not os.path.exists(path):response = requests.get(media_url)response.raise_for_status()  # 如果请求出错,这里会抛出HTTPError异常with open(path, "wb") as f:f.write(response.content)print("文件保存成功")else:print("文件已存在,未进行下载")
except requests.RequestException as e:print(f"请求错误: {e}")
except Exception as e:print(f"发生错误: {e}")

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com