furas

przykład na facebook

Apr 12th, 2020
265
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. html = '''<form class="col-xs-12"> <script type="text/javascript">
  2.  
  3.    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};
  4.    
  5.    </script>'''
  6.  
  7. from bs4 import BeautifulSoup as BS
  8. import json
  9.  
  10. soup = BS(html, 'lxml')
  11.  
  12. text = soup.find('script').text
  13. lines = text.splitlines()
  14. text = lines[2]
  15. text = text.strip()
  16. text = text[13:-1]
  17.  
  18. data = json.loads(text)
  19. #print(data)
  20.  
  21. for key, value in data.items():
  22.     print(key, '->', value)
  23.  
  24.  
  25. # Wynik
  26.  
  27. """
  28. 938975 -> True
  29. 938977 -> True
  30. 938979 -> True
  31. 938981 -> True
  32. 938983 -> True
  33. 938985 -> True
  34. 938987 -> False
  35. 938989 -> True
  36. 938991 -> True
  37. 938993 -> True
  38. 938995 -> True
  39. 938997 -> False
  40. 938999 -> True
  41. 939001 -> True
  42. 939003 -> True
  43. 939005 -> True
  44. 939007 -> True
  45. """
RAW Paste Data