加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

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

发布时间:2020-12-16 19:38:55 所属栏目:Python 来源:网络整理
导读:直接上代码: 复制代码 代码如下: span style="font-family: arial,helvetica,sans-serif; font-size: 16px;"# -*- coding: cp936 -*- import urllib import os print 'Download data......' url = 'http://cn.bing.com' urlFile = urllib.urlopen(url) data =
直接上代码:
复制代码 代码如下:

<span style="font-family: arial,helvetica,sans-serif; font-size: 16px;"># -*- coding: cp936 -*-
import urllib
import os

print '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>今日图片故事</h3><a href='
index3 = data.find(preImg) + len(preImg)
index4 = data.find('>',index3) + 1
index5 = 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)
</span>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读