forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
scrap_file.py
38 lines (26 loc) · 966 Bytes
/
scrap_file.py
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
# Author : RIZWAN AHMAD
# pip3 install requests
import requests
# Function for download file parameter taking as url
def download(url):
f = open(
"file_name.jpg", "wb"
) # opening file in write binary('wb') mode with file_name.ext ext=extension
f.write(requests.get(url).content) # Writing File Content in file_name.jpg
f.close()
print("Succesfully Downloaded")
# Function is do same thing as method(download) do,but more strict
def download_2(url):
try:
response = requests.get(url)
except Exception:
print("Failed Download!")
else:
if response.status_code == 200:
with open("file_name.jpg", "wb") as f:
f.write(requests.get(url).content)
print("Succesfully Downloaded")
else:
print("Failed Download!")
url = "https://avatars0.githubusercontent.com/u/29729380?s=400&v=4" # URL from which we want to download
download(url)