Guest User

Untitled

a guest
Jun 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. <script type='text/javascript' data-cfasync='false'>
  2. //<![CDATA[
  3. _SHR_SETTINGS = {"endpoints":{"local_recs_url":"https://klaudynahebda.pl/wp-admin/admin-ajax.php?action=shareaholic_permalink_related"},"url_components":{"year":"2018","monthnum":"06","day":"19","post_id":"21132","postname":"letnie-warsztaty-ziolowo-kosmetyczne-7-9lipiec","author":"admin"}};
  4. //]]>
  5. </script>
  6.  
  7. from bs4 import BeautifulSoup
  8.  
  9. html = """
  10. <script type='text/javascript' data-cfasync='false'>
  11. //<![CDATA[
  12. _SHR_SETTINGS = {"endpoints":{"local_recs_url":"https://klaudynahebda.pl/wp-admin/admin-ajax.php?action=shareaholic_permalink_related"},"url_components":{"year":"2018","monthnum":"06","day":"19","post_id":"21132","postname":"letnie-warsztaty-ziolowo-kosmetyczne-7-9lipiec","author":"admin"}};
  13. //]]>
  14. </script>
  15. """
  16.  
  17. soup = BeautifulSoup(html, 'lxml')
  18.  
  19. dct = {}
  20.  
  21. for scr in soup.find_all('script'):
  22. for x in scr.text.split(','):
  23. if 'post_id' in x:
  24. k, v = x.replace('"', '').split(':')
  25. dct[k] = v
  26.  
  27. print(dct['post_id'])
  28.  
  29. 21132
  30.  
  31. import re
  32. s = """<script type='text/javascript' data-cfasync='false'>
  33. //<![CDATA[
  34. _SHR_SETTINGS = {"endpoints":{"local_recs_url":"https://klaudynahebda.pl/wp-admin/admin-ajax.php?action=shareaholic_permalink_related"},"url_components":{"year":"2018","monthnum":"06","day":"19","post_id":"21132","postname":"letnie-warsztaty-ziolowo-kosmetyczne-7-9lipiec","author":"admin"}};
  35. //]]>
  36. </script>"""
  37. m = re.search(r'(?<="post_id":")(?P<post_id>.*?)(?=",")', s)
  38. if m:
  39. print(m.group('post_id'))
  40.  
  41. 21132
Add Comment
Please, Sign In to add comment