python中我用wb方式打开文件,报错说没有此文件?

wb明明是文件存在就将其覆盖不存在就创建新文件,为什么还会报错?代码如下:A=requests.get(a) soup=BeautifulSoup(A.text,features="lxml") name=str(soup.find('title').text).strip(lu) if e in range(7, 11): response=requests.get("https://music.163.com/song/media/outer/url?id=" + d[0] + ".mp3") with open(name+'.mp3',mode='wb') as f: f.write(response.content) f.close()

第1个回答  2020-08-11
有可能是name赋值失败(明显取决于网页内容,但你的写法太不健壮,建议正则提取),你先把name的值打印出来看看
第2个回答  2020-08-11
文件名里不能有/,这是路径分隔符。
相似回答