Dump () missing 1 required positional argument: 'fp' in python json

I try a json format prefix, but I get this error:

import requests as tt
from bs4 import BeautifulSoup
import json

get_url=tt.get("https://in.pinterest.com/search/pins/?rs=ac&len=2&q=batman%20motivation&eq=batman%20moti&etslf=5839&term_meta[]=batman%7Cautocomplete%7Cundefined&term_meta[]=motivation%7Cautocomplete%7Cundefined")
soup=BeautifulSoup(get_url.text,"html.parser")

select_css=soup.select("script#jsInit1")[0]
for i in select_css:
    print(json.dump(json.loads(i),indent=4,sort_keys=True))

Basically, I want to extract this type of element:

'orig': {'width': 1080, 'url': '', 'height': 1349},

I know I can do it with

select_css.get('orig').get('url')

But I'm not sure if this json element is a nested element under any element? That's why I'm trying to exaggerate to get an idea.

+4
source share
1 answer

Use json.dumps()instead. json.dump()need a file object and a JSON dump.

+16
source

Source: https://habr.com/ru/post/1686314/


All Articles