Oct-22-2016, 05:39 PM
(Oct-22-2016, 04:46 PM)snippsat Wrote:Oh, i understand.import requests import re import json url = "https://www.instagram.com/p/BLExlG_gs9M/" url_get = requests.get(url) sorurce = url_get.text data_json = re.findall(r'<script type="text/javascript">window._sharedData = (.*);</script>', sorurce)[0] data = json.loads(data_json)Use it:
>>> data['entry_data']['PostPage'][0]['media']['caption'] '#Plebiscito 2016'json.loads() give back a python dictionary.
In this dictionary there is a mix of dictionary/list.
Here dos ['PostPage'][0] contain a list,
therefor [0] to get get contented inside this list and continue to navigate.
I will try with the comments(text):
print(data['entry_data']['PostPage'][0]['media']['comments']) #print(data['entry_data']['PostPage'][0]['media']['comments']['nodes']['text']) #Error **sad**
Output:{'page_info': {'has_next_page': False, 'start_cursor': None, 'end_cursor': None, 'has_previous_page': False}, 'nodes': [{'text': '@youngfelprefe listo ya voto tambn bien mijo★', 'user': {'profile_pic_url': 'http://scontent-lax3-1.cdninstagram.com/t51.2885-19/11906329_960233084022564_1448528159_a.jpg', 'id': '2298791058', 'username': 'luisfelipetv'}, 'id': '17862897478024941', 'created_at': 1475442983.0}, {'text': 'Si', 'user': {'profile_pic_url': 'https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/s150x150/14156414_1079735282112695_1636583007_a.jpg', 'id': '202000611', 'username': 'omeganr'}, 'id': '17862897862024941', 'created_at': 1475443748.0}, {'text': '?\U0001f3fb', 'user': {'profile_pic_url': 'https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/s150x150/14676778_1715076945484909_6612390138339131392_a.jpg', 'id': '479496344', 'username': 'nandocolombia'}, 'id': '17862899284024941', 'created_at': 1475446598.0}, {'text': 'Por el NOO te conozco tanto jajajajaaj', 'user': {'profile_pic_url': 'https://igcdn-photos-f-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/s150x150/14736230_1778075029077069_7479698963461832704_a.jpg', 'id': '261070560', 'username': 'lauspath'}, 'id': '17862899803024941', 'created_at': 1475447612.0}, {'text': 'Primo Jaja ??', 'user': {'profile_pic_url': 'https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/s150x150/14553081_161587474301255_7594124386945204224_a.jpg', 'id': '3021395284', 'username': 'jhonny_reyes23'}, 'id': '17862900988024941', 'created_at': 1475448945.0}, {'text': 'Por el simple hecho de dar tu nombre completo, es sencillo buscar tu número de cédula.', 'user': {'profile_pic_url': 'https://igcdn-photos-h-a.akamaihd.net/hphotos-ak-xpa1/t51.2885-19/s150x150/13381051_2033323503560343_1374158480_a.jpg', 'id': '646190648', 'username': 'jjargel'}, 'id': '17862953830024941', 'created_at': 1475519921.0}], 'count': 6}