Skip to content

Instantly share code, notes, and snippets.

@bauripalash
Created April 25, 2020 13:04
Show Gist options
  • Save bauripalash/33aa9c32eed5d0ca58847d9c17bff340 to your computer and use it in GitHub Desktop.
Save bauripalash/33aa9c32eed5d0ca58847d9c17bff340 to your computer and use it in GitHub Desktop.
from bs4 import BeautifulSoup as bs
import sys
import requests
def main():
if len(sys.argv) == 2:
URL = sys.argv[1]
soup = bs(requests.get(URL).content , "html.parser")
for image in soup.find_all("img"):
if image["src"]:
img = image["src"] if image["src"].startswith("http") else URL + image["src"]
r = requests.get(img, stream = True)
with open(img.split("/")[-1] , "wb") as f:
for ch in r:
f.write(ch)
else:
print("Usage: python imgdown.py <URL>")
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment