Skip to content

Commit 86134a2

Browse files
committed
Update scrap_file.py
1 parent 791e09b commit 86134a2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

scrap_file.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,21 @@ def download(url):
1616
f.close()
1717
print("Succesfully Downloaded")
1818

19+
#Function is do same thing as method(download) do,but more strict
20+
def download_2(url):
21+
try:
22+
response = requests.get(url)
23+
except Exception:
24+
print('Failed Download!')
25+
else:
26+
if response.status_code == 200:
27+
with open('file_name.jpg','wb') as f:
28+
f.write(requests.get(url).content)
29+
print("Succesfully Downloaded")
30+
else:
31+
print('Failed Download!')
32+
1933
url='https://avatars0.githubusercontent.com/u/29729380?s=400&v=4' #URL from which we want to download
20-
34+
2135
download(url)
2236

0 commit comments

Comments
 (0)