鱼C论坛

 找回密码
 立即注册
查看: 1992|回复: 1

open函数被os库里的更新了,该如何使用之前的open函数

[复制链接]
发表于 2019-10-16 11:01:38 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
import requests
import os
url = 'https://image.baidu.com/search/detail?ct=503316480&z=0&ipn=false&word=%E5%8A%A8%E6%BC%AB%E5%9B%BE%E7%89%87%20%E5%A4%B4%E5%83%8F&step_word=&hs=2&pn=1&spn=0&di=990&pi=0&rn=1&tn=baiduimagedetail&is=0%2C0&istype=2&ie=utf-8&oe=utf-8&in=&cl=2&lm=-1&st=-1&cs=2125498181%2C471266719&os=2329743207%2C2717747748&simid=0%2C0&adpicid=0&lpn=0&ln=2116&fr=&fmq=1389861203899_R&fm=&ic=0&s=undefined&hd=undefined&latest=undefined&copyright=undefined&se=&sme=&tab=0&width=&height=&face=undefined&ist=&jit=&cg=head&bdtype=0&oriquery=%E5%8A%A8%E6%BC%AB%E5%9B%BE%E7%89%87&objurl=http%3A%2F%2Fimg3.duitang.com%2Fuploads%2Fitem%2F201605%2F21%2F20160521112458_PeXvw.jpeg&fromurl=ippr_z2C%24qAzdH3FAzdH3Fooo_z%26e3B17tpwg2_z%26e3Bv54AzdH3Fks52AzdH3F%3Ft1%3Dc0ba0nnd0&gsm=&rpstart=0&rpnum=0&islist=&querylist=&force=undefined'
root = 'E://'
path = root + url.split('/')[-1]
try:
    if not os.path.exists(root):
        os.mkdir(root)
    if not os.path.exists(path):
        r = requests.get(url)
        #print(r.status_code)
        #print(os.getcwd())
        with open(path, 'wb') as f:
            f.write(r.content)
            f.close()
            print('文件保存成功')

    else:
        print('文件已存在')
except:
    print('爬取失败')
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-10-16 14:52:10 From FishC Mobile | 显示全部楼层
你想问啥
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

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

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-20 02:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表