Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # author: Bartlomiej "furas" Burek (https://blog.furas.pl)
- # 2020.05.12
- html = '''<form class="col-xs-12"> <script type="text/javascript">
- var stocks = {"938975":true,"938977":true,"938979":true,"938981":true,"938983":true,"938985":true,"938987":false,"938989":true,"938991":true,"938993":true,"938995":true,"938997":false,"938999":true,"939001":true,"939003":true,"939005":true,"939007":true};
- </script>'''
- from bs4 import BeautifulSoup as BS
- import json
- soup = BS(html, 'lxml')
- text = soup.find('script').text
- lines = text.splitlines()
- text = lines[2]
- text = text.strip()
- text = text[13:-1]
- data = json.loads(text)
- #print(data)
- for key, value in data.items():
- print(key, '->', value)
- # Result
- """
- 938975 -> True
- 938977 -> True
- 938979 -> True
- 938981 -> True
- 938983 -> True
- 938985 -> True
- 938987 -> False
- 938989 -> True
- 938991 -> True
- 938993 -> True
- 938995 -> True
- 938997 -> False
- 938999 -> True
- 939001 -> True
- 939003 -> True
- 939005 -> True
- 939007 -> True
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement