马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 fresh_python 于 2020-5-20 19:48 编辑
今天5月20号,献上爬取52张520图片的代码。(图片来源于百度图片)如有不足欢迎大家指正import json
import requests
import os
path = os.getcwd()
photo_path = path+os.sep+'520图片'
try:
os.mkdir(photo_path)
except:
pass
def save(url,each):#保存图片
try:
response = requests.get(url)
filename = photo_path+os.sep+str(each)+'.jpg'
print('正在下载图片%d'%(each+1))
with open(filename,'wb') as f:
f.write(response.content)
except:
print('下载失败')
def main():
url = 'https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=0%2C0&fp=detail&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=0&lpn=0&st=undefined&word=520&z=0&ic=undefined&hd=undefined&latest=undefined©right=undefined&s=undefined&se=&tab=0&width=undefined&height=undefined&face=undefined&istype=0&qc=&nc=&fr=&simics=&srctype=&bdtype=0&rpstart=0&rpnum=0&cs=2865499277%2C3199044538&catename=&force=undefined&cardserver=&tabname=&pn=0&rn=60&gsm=1f&1589961222385='
response = requests.get(url)
data = json.loads(response.text)
for each in range(52):
url1 = str(data['data'][each]['hoverURL'])
save(url1,each)
if __name__=='__main__':
main()
|