Python Forum
Extracting Specific Lines from text file based on content.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Extracting Specific Lines from text file based on content.
#5
deanhystad Wrote:resp.json is a json string with all the interesting stuff. You can convert the json string to a Python dictionary to make it easier to work with.
deanhystad as info so do Requests have build in json encoder/decoder added a long time ago(2014).
So the extra step with json string trough json library is not recommend.
can also mess up encoding,resp.json() directly from Request dos a much better job of figuring out encoding used.
>>> import requests
>>> 
>>> resp = requests.get('https://github.com/timeline.json')
>>> resp.json()
{'documentation_url': 'https://docs.github.com/v3/activity/events/#list-public-events',
 'message': 'Hello there, wayfaring stranger. If you’re reading this then you '
            'probably didn’t see our blog post a couple of years back '
            'announcing that this API would go away: http://git.io/17AROg Fear '
            'not, you should be able to get what you need from the shiny new '
            'Events API instead.'}

>>> resp.json()['documentation_url']
'https://docs.github.com/v3/activity/events/#list-public-events'

>>> resp.encoding
'utf-8'
Reply


Messages In This Thread
RE: Extracting Specific Lines from text file based on content. - by snippsat - Mar-25-2022, 09:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Copy Paste excel files based on the first letters of the file name Viento 2 493 Feb-07-2024, 12:24 PM
Last Post: Viento
  Extracting specific file from an archive tester_V 4 571 Jan-29-2024, 06:41 PM
Last Post: tester_V
  Color a table cell based on specific text Creepy 11 2,143 Jul-27-2023, 02:48 PM
Last Post: deanhystad
  Split pdf in pypdf based upon file regex standenman 1 2,152 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,167 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Reading Specific Rows In a CSV File finndude 3 1,022 Dec-13-2022, 03:19 PM
Last Post: finndude
  How to remove footer from PDF when extracting to text jh67 3 5,241 Dec-13-2022, 06:52 AM
Last Post: DPaul
  reading content between a specific xml tag saisankalpj 1 881 Oct-31-2022, 01:37 PM
Last Post: wavic
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 1,302 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  Delete multiple lines from txt file Lky 6 2,374 Jul-10-2022, 12:09 PM
Last Post: jefsummers

Forum Jump:

User Panel Messages

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