Parsing a JSON file with BeautifulSoup
17,851
The HTML content is wrapped in a JSON. For your example, you can try:
url = "https://www.youtube.com/browse_ajax?action_continuation=1&continuation=4qmFsgIuEiRWTFBMbFRwZUhIS2o1TFNpRVpKbXJxZGg0MHlqZjBmdG4xak4aBkNHVSUzRA%253D%253D"
lm_json = requests.get(url).json()
soup = BeautifulSoup(lm_json["content_html"])
Author by
Admin
Updated on June 04, 2022Comments
-
Admin almost 2 years
Fairly new to coding so bear with me for any fundamental mistakes. Simplified, I have this:
url = "https://www.youtube.com/browse_ajax?action_continuation=1&continuation=4qmFsgIuEiRWTFBMbFRwZUhIS2o1TFNpRVpKbXJxZGg0MHlqZjBmdG4xak4aBkNHVSUzRA%253D%253D" lm_json = requests.get(url).json()
How would I go about parsing
lm_json
with BeautifulSoup? I keep getting errors to open it as a file. I need to use BeautifulSoup because I'm using the result in a while loop.From this step, I'd need to append it to the main soup.
Thanks for any help!
-
Admin almost 8 yearsI'm getting
AttributeError: 'dict' object has no attribute 'content_html'
EDIT: just triedlm_soup = BeautifulSoup(lm_json['content_html'])
and it seems to be parsing correctly