Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > Python多媒体

使用Python下载Bing图片(代码)

来源:中文源码网    浏览:156 次    日期:2024-04-27 00:41:04
【下载文档:  使用Python下载Bing图片(代码).txt 】


使用Python下载Bing图片(代码)
直接上代码:复制代码 代码如下:# -*- coding: cp936 -*-import urllibimport osprint 'Download data......'url = 'http://cn.bing.com'urlFile = urllib.urlopen(url)data = urlFile.read()urlFile.close()data = data.decode('utf-8')pre = 'g_img={url:\''index1 = data.find(pre) + len(pre)index2 = data.find('\'', index1)imgUrl = data[index1 : index2]preImg = u'h3>今日图片故事', index3) + 1index5 = data.find('<', index4)imgName = data[index4 : index5] +u'.jpg'if os.path.exists(imgName) == False: print 'Download image......' urllib.urlretrieve(imgUrl, imgName)print 'Download complete'os.startfile(imgName)

相关内容