FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python/bing_photos.py at master · Idris-RAD/learn-python · GitHub
Idris-RAD
/
learn-python
Public
forked from
tanteng/learn-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python
/
bing_photos.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
50 lines (28 loc) · 1.05 KB
Breadcrumbs
learn-python
/
bing_photos.py
Copy path
File metadata and controls
50 lines (28 loc) · 1.05 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# -*- author:arron ni-*-
# python3抓取bing主页所有背景图片
import
urllib
.
request
import
re
import
sys
import
os
def
get_bing_backphoto
():
if
os
.
path
.
exists
(
'photos'
)
==
False
:
os
.
mkdir
(
'photos'
)
for
i
in
range
(
0
,
30
):
url
=
'http://cn.bing.com/HPImageArchive.aspx?format=js&idx='
+
str
(
i
)
+
'&n=1&nc=1361089515117&FORM=HYLH1'
html
=
urllib
.
request
.
urlopen
(
url
).
read
()
if
html
==
'null'
:
print
(
'open & read bing error!'
)
sys
.
exit
(
-
1
)
html
=
html
.
decode
(
'utf-8'
)
reg
=
re
.
compile
(
'"url":"(.*?)","urlbase"'
,
re
.
S
)
text
=
re
.
findall
(
reg
,
html
)
# http://s.cn.bing.net/az/hprichbg/rb/LongJi_ZH-CN8658435963_1366x768.jpg
for
imgurl
in
text
:
right
=
imgurl
.
rindex
(
'/'
)
name
=
imgurl
.
replace
(
imgurl
[:
right
+
1
],
''
)
savepath
=
'photos/'
+
name
urllib
.
request
.
urlretrieve
(
imgurl
,
savepath
)
print
(
name
+
' save success!'
)
get_bing_backphoto
()
Back
|
FazBrowse Home
|
New Git URL