Python Forum
extracting data from json on website
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
extracting data from json on website
#2
this json is array of objects, or converted to python terms - list of dicts

import requests
url="https://raw.githubusercontent.com/kovidgoyal/build-calibre/master/scripts/sources.json"
data = requests.get(url).json()
print data[:3]
print '\n\n'
for obj in data[:3]:
    for key, value in obj.items():
        print('{} --> {}'.format(key, value))
    print('')
Output:
[{u'unix': {u'hash': u'sha256:4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea 0a2114e19bf066', u'urls': [u'http://zlib.net/{filename}'], u'filename': u'zlib-1 .2.11.tar.xz'}, u'name': u'zlib'}, {u'unix': {u'hash': u'md5:00b516f4704d4a7cb50 a1d97e6e8e15b', u'urls': [u'http://www.bzip.org/1.0.6/{filename}'], u'filename': u'bzip2-1.0.6.tar.gz'}, u'name': u'bzip2'}, {u'unix': {u'hash': u'sha1:f4fa1c41 42b497356a3df505e1459c188f646fad', u'urls': [u'http://www.rarlab.com/rar/{filena me}'], u'filename': u'unrarsrc-5.5.8.tar.gz'}, u'name': u'unrar'}] unix --> {u'hash': u'sha256:4ff941449631ace0d4d203e3483be9dbc9da454084111f97ea0a 2114e19bf066', u'urls': [u'http://zlib.net/{filename}'], u'filename': u'zlib-1.2 .11.tar.xz'} name --> zlib unix --> {u'hash': u'md5:00b516f4704d4a7cb50a1d97e6e8e15b', u'urls': [u'http://w ww.bzip.org/1.0.6/{filename}'], u'filename': u'bzip2-1.0.6.tar.gz'} name --> bzip2 unix --> {u'hash': u'sha1:f4fa1c4142b497356a3df505e1459c188f646fad', u'urls': [u 'http://www.rarlab.com/rar/{filename}'], u'filename': u'unrarsrc-5.5.8.tar.gz'} name --> unrar >>>
Reply


Messages In This Thread
extracting data from json on website - by larry2311 - Feb-08-2018, 06:07 AM
RE: extracting data from json on website - by buran - Feb-08-2018, 08:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Extracting the correct data from a CSV file S2G 6 418 Jun-03-2024, 04:50 PM
Last Post: snippsat
  encrypt data in json file help jacksfrustration 1 527 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Scraping Data from Website melkaray 3 960 Sep-22-2023, 12:41 PM
Last Post: melkaray
  Extracting Data into Columns using pdfplumber arvin 17 6,427 Dec-17-2022, 11:59 AM
Last Post: arvin
  Read nested data from JSON - Getting an error marlonbown 5 1,604 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,247 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Code to retrieve data from a website charlie13255 0 1,075 Jul-07-2022, 07:53 PM
Last Post: charlie13255
  Is this possible to write a script for checking data from website? WanW 2 1,244 Jun-02-2022, 02:31 AM
Last Post: Larz60+
  Convert nested sample json api data into csv in python shantanu97 3 3,153 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 2,150 May-09-2022, 02:49 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

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