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

Time:01-20

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:

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!

CodePudding user response:

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
  •  Tags:  
  • Related