Skip to content

Commit

Permalink
Create instagram_pic (TheAlgorithms#3945)
Browse files Browse the repository at this point in the history
* Create instagram_pic

* Update instagram_pic

* Update instagram_pic

* isort

* Update instagram_pic.py

Co-authored-by: Christian Clauss <[email protected]>
  • Loading branch information
Epic-R-R and cclauss authored Nov 24, 2020
1 parent 3fdbf97 commit e031ad3
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions web_programming/instagram_pic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from datetime import datetime

import requests
from bs4 import BeautifulSoup

if __name__ == "__main__":
url = input("Enter image url: ").strip()
print(f"Downloading image from {url} ...")
soup = BeautifulSoup(requests.get(url).content, "html.parser")
# The image URL is in the content field of the first meta tag with property og:image
image_url = soup.find("meta", {"property": "og:image"})["content"]
image_data = requests.get(image_url).content
file_name = f"{datetime.now():%Y-%m-%d_%H:%M:%S}.jpg"
with open(file_name, "wb") as fp:
fp.write(image_data)
print(f"Done. Image saved to disk as {file_name}.")

0 comments on commit e031ad3

Please sign in to comment.