Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use Pythonista to download an image from Instagram. Usage via the share extension or run it straight from your home screen (in this case it will get the url from the iOS clipboard). Save this file in the 'This Phone' path in Pythonista, then download this shortcut:
# this script is for Pythonista 2 and 3
# author: Francesco Pira (
import sys
import requests
from bs4 import BeautifulSoup
import re
import clipboard
import Image
import photos
from urllib import urlopen
from io import BytesIO
import console
# if no arg is passed (aka you're not running it from Share Extension,
# get the url from iOS clipboard)
source_url = sys.argv[1] if len(sys.argv) > 1 else clipboard.get()
if not source_url:
console.alert('Sorry, no URL given!','','OK',hide_cancel_button=True)
r = requests.get(source_url)
for line in r:
html_doc = html_doc + line
soup = BeautifulSoup(html_doc, 'html.parser')
for meta in soup.find_all(re.compile("^meta")):
tags = meta.attrs
if 'property' in tags:
if tags['property'] == 'og:image':
img_url = tags['content']
img =
console.alert('Image saved in Photos','','OK',hide_cancel_button=True)
console.alert('Oops! Something went wrong... Please check your clipboard!','','OK',hide_cancel_button=True)

This comment has been minimized.

Copy link
Owner Author

@pirafrank pirafrank commented Oct 27, 2020

You can see it in action in this video.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment