Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ReGex With Python
#30
(Oct-22-2016, 04:46 PM)snippsat Wrote:
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.
Oh, i understand. 
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}
Reply


Messages In This Thread
ReGex With Python - by Kalet - Oct-21-2016, 08:29 PM
RE: ReGex With Python - by nilamo - Oct-21-2016, 08:43 PM
RE: ReGex With Python - by Kalet - Oct-21-2016, 08:52 PM
RE: ReGex With Python - by nilamo - Oct-21-2016, 08:59 PM
RE: ReGex With Python - by Kalet - Oct-21-2016, 09:05 PM
RE: ReGex With Python - by nilamo - Oct-21-2016, 09:19 PM
RE: ReGex With Python - by Kalet - Oct-21-2016, 09:24 PM
RE: ReGex With Python - by Ofnuts - Oct-21-2016, 10:00 PM
RE: ReGex With Python - by Kalet - Oct-21-2016, 10:09 PM
RE: ReGex With Python - by snippsat - Oct-21-2016, 10:37 PM
RE: ReGex With Python - by Kalet - Oct-21-2016, 10:56 PM
RE: ReGex With Python - by snippsat - Oct-21-2016, 11:13 PM
RE: ReGex With Python - by Kalet - Oct-21-2016, 11:26 PM
RE: ReGex With Python - by snippsat - Oct-21-2016, 11:31 PM
RE: ReGex With Python - by Kalet - Oct-21-2016, 11:48 PM
RE: ReGex With Python - by snippsat - Oct-21-2016, 11:59 PM
RE: ReGex With Python - by Kalet - Oct-22-2016, 12:05 AM
RE: ReGex With Python - by snippsat - Oct-22-2016, 12:07 AM
RE: ReGex With Python - by Kalet - Oct-22-2016, 12:15 AM
RE: ReGex With Python - by snippsat - Oct-22-2016, 12:22 AM
RE: ReGex With Python - by Kalet - Oct-22-2016, 12:31 AM
RE: ReGex With Python - by snippsat - Oct-22-2016, 12:56 AM
RE: ReGex With Python - by Kalet - Oct-22-2016, 01:04 AM
RE: ReGex With Python - by snippsat - Oct-22-2016, 01:15 AM
RE: ReGex With Python - by Kalet - Oct-22-2016, 01:25 AM
RE: ReGex With Python - by snippsat - Oct-22-2016, 01:46 AM
RE: ReGex With Python - by Kalet - Oct-22-2016, 03:13 AM
RE: ReGex With Python - by Kalet - Oct-22-2016, 04:18 PM
RE: ReGex With Python - by snippsat - Oct-22-2016, 04:46 PM
RE: ReGex With Python - by Kalet - Oct-22-2016, 05:39 PM
RE: ReGex With Python - by snippsat - Oct-22-2016, 05:58 PM
RE: ReGex With Python - by Kalet - Oct-22-2016, 06:36 PM
RE: ReGex With Python - by Kalet - Oct-23-2016, 10:21 PM
RE: ReGex With Python - by sparkz_alot - Oct-24-2016, 12:23 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020