11.11爬虫学习
自动取文件名:
import os
import requests
p2='E://test1/'
url='https://img0.baidu.com/it/u=281429383'
p4=url.split('/')[-2]+'.jpg'
p3=p2+p4
if not os.path.exists(p2):
os.mkdir(p2)
r=requests.get(url)
r.encoding=r.apparent_encoding
a=r.content
with open(p3,'wb')as f:
f.write(a)
f.close()
lujing, filename = os.path.split(p3)
print("路径:", mulu)
print("文件名:", filename)