Skip to content

Instantly share code, notes, and snippets.

@hakanu
Created October 16, 2020 00:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakanu/f81d97c47d6d84d48812385195eca211 to your computer and use it in GitHub Desktop.
Save hakanu/f81d97c47d6d84d48812385195eca211 to your computer and use it in GitHub Desktop.
[paylas.io/r/python] Instagram'dan foto indirme scripti
import json
import requests
import re
html = requests.get('https://www.instagram.com/instagram/').text
print('Instagramdan cektigim html boyutu: ', len(html))
pattern = '<script type="text\/javascript">window._sharedData = (.*?);<\/script>'
match_results = re.findall(pattern, html)
match_result = None
if not match_results:
print('HTMLde veri yok muhtemelen private profil.')
exit()
match_result = match_results[0]
imgs = []
try:
imgs = json.loads(match_result)['entry_data']['ProfilePage'][0]['graphql']['user']['edge_owner_to_timeline_media']['edges']
except Exception as e:
print('Bisiler yanlis gitti', e)
exit()
for img in imgs:
img = img['node']
if img['__typename'] == 'GraphImage':
shortcode = img['shortcode']
url = img['display_url']
print('Indirilen post: https://instagram.com/p/' + shortcode)
response = requests.get(url)
with open(shortcode + '.png', 'wb') as f:
f.write(response.content)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment