I've seen some similar questions, but not quite what I'm asking (that I could find at least). I'm using the bottom three lines of code to make an api request that returns various aspects of an article.
response = requests.get(self.format_url(api, version), params=payload)
json_data = response.json()
return json_data
The data I request comes back fine, and I've figured out how to extract the text parameter like I want. The only problem is I want to preserve paragraph breaks, but article_text
below is just all the text having ignored paragraph breaks. Is there a standard way to do this with json or is it completely dependent on the API I'm using? Thanks for your help, I'm new to python!
article_text = json_data['objects'][0]['text']
Just in case anyone happens to read this, the solution I implemented was to pull the unaltered html from json_data
then utilize beautiful soup to format the text by searching for all
tags and replacing them with
tags. That worked.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.