版权声明:转载请注明出处。 https://blog.csdn.net/Xin_101/article/details/82177332
1 Python爬取水墨画图片
源码
import requests
import json
import urllib
n = 0
m = 0
def getSogouImag(length,path):
global m
n = length
requests.get('http://pic.sogou.com/pics/channel/getAllRecomPicByTag.jsp?category='+cate+'&tag=%E5%85%A8%E9%83%A8&start=0&len='+str(n))
imgs = requests.get('http://pic.sogou.com/pics?query=%CB%AE%C4%AB%BB%AD&mode=1&start='+str(n)+'&reqType=ajax&tn=0&reqFrom=detail')
jd = json.loads(imgs.text)
jd = jd['items']
imgs_url = []
for j in jd:
imgs_url.append(j['thumbUrl'])
for img_url in imgs_url:
print('No.'+str(m)+'.jpg '+' is Downloading...')
urllib.request.urlretrieve(img_url,path+str(m)+'.jpg')
m = m + 1
while n < 20:
getSogouImag(n,'/your path/inkpainting/')
n+=1
else:
print('Download complete!')
结果
2 几点说明
- 爬取水墨画需分批爬取
- 全局变量在函数中使用需要添加global关键字
- 每一批图片在items项目下
- 图片url使用thumburl
3 图片url提取
4 小结
本文是在Ubuntu18.04环境查看图片URL,windows环境下,查看URL出现问题。
爬取图片需分析URL构成及爬去的图片数量。
【参考文献】
[1]https://www.jb51.net/article/109222.htm
[2]https://blog.csdn.net/my2010sam/article/details/17735159