本文主要是介绍python根据关键词爬取bing图片(缩略图mimg),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
关键词是中文
# 从得到的图片链接下载图片,并保存
import os
import time
import urllibimport requests
from bs4 import BeautifulSoupdef SaveImage(link, InputData, count):try:time.sleep(1)urllib.request.urlretrieve(link, './pic/' + InputData + '/' + str(count) + '.jpg')except Exception:time.sleep(1)print("产生未知错误,放弃保存")else:print("图+1,已有" + str(count) + "张图")# 找到图片的链接
def FindLink(PageNum, InputData, word):for i in range(PageNum):print(i)try:url = 'https://cn.bing.com/images/async?q=Grape+sunscald&first=128&count=35&relp=35&scenario' \'=ImageBasicHover&datsrc=N_I&layout=RowBased_Landscape&mmasync=1&dgState=x*0_y*0_h*0_c*5_i*106_r*18' \'&IG=5FDF1FE62E2C42519A9C076C6DC3919A&SFX=4&iid=images.5531 '# url = 'http://cn.bing.com/images/async?q={0}&first={1}&count=35&relp=35&scenario=ImageBasicHover&' \# 'datsrc=N_I&layout=RowBased_Landscape&SFX=2'\# '&mmasync=1&dgState=x*533_y*1190_h*188_c*2_i*36_r*7'# 定义请求头url2 = 'https:
这篇关于python根据关键词爬取bing图片(缩略图mimg)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!