import requests
import re
urls = 'https://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1553158259919_R&pv=&ic=&nc=1&z=&hd=&latest=©right=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&ie=utf-8&hs=2&word=德国牧羊犬'
response = requests.get(urls)
response.encoding = 'utf-8'
html = response.text
scrap_urls = re.findall(r'"thumbURL":"(.*?)"',html)
path_name = r'F:\jupyternb\keras\zhengzhengclass\scrapy\scrap_img'
d_type = ['哈士奇', '德国牧羊犬', '拉布拉多', '萨摩耶犬']
i = 0
for index,scrap_url in enumerate(scrap_urls):
response = requests.get(scrap_url)
i += 1
if i>28:
break
with open('%s/%s/0_%s.%s' %(path_name,d_type[1],index,scrap_url.split('.')[-1]),'wb') as f:
f.write(response.content)