forked from iloster/PythonScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbing.py
More file actions
31 lines (28 loc) · 725 Bytes
/
bing.py
File metadata and controls
31 lines (28 loc) · 725 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#-*-coding:utf-8 -*-
#-----------------------------
# python2.7
# author:loster
# version:0.1
# description:下载bing壁纸到本地
#-------------------------------
import urllib
import re
import time
def getHtml(url):
return urllib.urlopen(url).read()
def getImgUrl(html):
reg=re.compile(r'(http://s.cn.bing.net/.*?\.jpg)')
url=reg.findall(html)
print url[0]
return url[0]
def downloadImg(url,path):
xpath=path+'\\bing.jpg'
print xpath
urllib.urlretrieve(url,xpath)
if __name__=='__main__':
start=time.time()
html=getHtml('http://cn.bing.com/')
url=getImgUrl(html)
downloadImg(url,'F:\\python')
end=time.time()
print 'done %.2f seconds' % (end-start)