FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
learn-python/save_remote_image.py at master · cscis/learn-python · GitHub
cscis
/
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
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
learn-python
/
save_remote_image.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
30 lines (24 loc) · 756 Bytes
Breadcrumbs
learn-python
/
save_remote_image.py
Copy path
File metadata and controls
30 lines (24 loc) · 756 Bytes
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
# -*- coding: utf-8 -*-
# 使用requests保存远程图片(或文件)
import
requests
import
os
def
saveRemoteImage
():
imgurl
=
'http://www.tantengvip.com/wp-content/uploads/2015/01/cropped-13887362_13887362_1347773771848.jpg'
filename
=
imgurl
.
split
(
'/'
)[
-
1
]
path
=
'./static/'
+
filename
if
not
os
.
path
.
exists
(
path
):
r
=
requests
.
get
(
imgurl
)
with
open
(
path
,
'wb'
)
as
f
:
f
.
write
(
r
.
content
)
print
(
'OK'
)
else
:
print
(
'Already exists.'
)
"""
下载大文件这样写:
for chunk in r.iter_content():
f.write(chunk)
如果不使用requests模块:
import urllib
urllib.urlretrieve(url, filename=None, reporthook=None, data=None)
"""
saveRemoteImage
()
Back
|
FazBrowse Home
|
New Git URL