Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to find specific json key:value in html with BeautifulSoup python

I have this html source: https://pastebin.com/F48CiZ6e

I am trying to get the value true from "userIsBlockedViaMessaging" key in the html source provided

I tried the following without luck:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

disabled_regex = ad_html_source.body.findAll(text=re.compile('"userIsBlockedViaMessaging"'))
disabled = str(re.compile('"userIsBlockedViaMessaging":(.+),', disabled_regex[0]).group())

If someone could help me out it would mean a lot!
Thanks!

>Solution :

You can use .*? as a regex pattern to search for the text true:

disabled = re.search(r'"userIsBlockedViaMessaging":(.*?),', str(soup)).group(1)
print(disabled)

Output:

true
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading