Apr-21-2021, 12:04 AM
(Apr-20-2021, 11:36 PM)snippsat Wrote:(Apr-20-2021, 11:01 PM)PopFendi Wrote: So, are you saying the correct method would be to search for all of the 'sub' and 'com' values first, before trying to search for a keyword within them?No was just demo how these libraries can help with a large nested return like this.
Not look at more precise what you want(describe it better),doge
as you talk about look just like a plain text and not a key in the nested dictionary.
Sorry, let me clarify.
'Doge' is the string I am trying to search for within the values of 'com' and 'sub'. If the 'Doge' string is found, I want it to return the value of 'no' (ie. the thread number) Perhaps my latest attempt might help to illustrate what I mean.
import requests import json response = requests.get('https://a.4cdn.org/biz/catalog.json') catalog = json.loads(response.text) for page in catalog: thread = page['threads'] for threads in thread: no = threads["no"] word = "doge" try: sub = threads["sub"] for value in sub: if word in value: print(no) except: pass try: com = threads["com"] for value in com: if word in value: print(no) except: continueI've added the try / except because some threads do not contain either a 'com' or a 'sub' key, and I was getting a traceback.
Hope that makes sense,
Thank you!