Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

beautifulsoup extract json from script elements

import json
from bs4 import BeautifulSoup

html = '''
<script type="application/json" data-initial-state="review-filter">
{"languages":[{"isoCode":"all","displayName":"Toutes les langues","reviewCount":"573"},{"isoCode":"fr","displayName":"français","reviewCount":"567"},{"isoCode":"en","displayName":"English","reviewCount":"6"}],"selectedLanguages":["all"],"selectedStars":null,"selectedLocationId":null}
</script>
'''

soup = BeautifulSoup(html, 'html.parser')
res = soup.find('script')
json_object = json.loads(res.contents[0])

for language in json_object['languages']:
    print('{}: {}'.format(language['displayName'], language['reviewCount']))
Comment

PREVIOUS NEXT
Code Example
Javascript :: on window resize react 
Javascript :: get random number in solidity 
Javascript :: laravel ajax post request 
Javascript :: how to get the first character of a string in javascript 
Javascript :: tolowercase javascript 
Javascript :: angular input press enter 
Javascript :: window.onload 
Javascript :: jquery delete request 
Javascript :: get id in jquery 
Javascript :: prevent form submit javascript 
Javascript :: document get element by tag 
Javascript :: header ejs 
Javascript :: update node-modules 
Javascript :: regex email js 
Javascript :: jquery clear select 2 
Javascript :: get query from url react router dom v6 
Javascript :: jquery datatable returning current datetime 
Javascript :: js random string 
Javascript :: sequelize like search 
Javascript :: show and hide div tag based on checkbox selection using jquery 
Javascript :: javascript replace part of string 
Javascript :: horizontal divider react native 
Javascript :: numeros primos js 
Javascript :: window loaded vanilla javascript 
Javascript :: javascript add required attribute to input 
Javascript :: jquery for table Show entries 
Javascript :: angular viewchild input element value 
Javascript :: remove css inline style javascript 
Javascript :: gitignore for angular 
Javascript :: js generate random boolean 
ADD CONTENT
Topic
Content
Source link
Name
7+8 =