Created
October 16, 2020 00:03
-
-
Save hakanu/f81d97c47d6d84d48812385195eca211 to your computer and use it in GitHub Desktop.
[paylas.io/r/python] Instagram'dan foto indirme scripti
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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