We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3e43bc8 commit a73daccCopy full SHA for a73dacc
web_programming/instagram_pic.py
@@ -0,0 +1,16 @@
1
+from datetime import datetime
2
+
3
+import requests
4
+from bs4 import BeautifulSoup
5
6
+if __name__ == "__main__":
7
+ url = input("Enter image url: ").strip()
8
+ print(f"Downloading image from {url} ...")
9
+ soup = BeautifulSoup(requests.get(url).content, "html.parser")
10
+ # The image URL is in the content field of the first meta tag with property og:image
11
+ image_url = soup.find("meta", {"property": "og:image"})["content"]
12
+ image_data = requests.get(image_url).content
13
+ file_name = f"{datetime.now():%Y-%m-%d_%H:%M:%S}.jpg"
14
+ with open(file_name, "wb") as fp:
15
+ fp.write(image_data)
16
+ print(f"Done. Image saved to disk as {file_name}.")
0 commit comments