You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

26 lines
967 B

from bs4 import BeautifulSoup
import sys
import json
from signal import signal, SIGPIPE, SIG_DFL
if __name__ == '__main__':
page = sys.stdin.read()
soup = BeautifulSoup(page, "html.parser")
script = [s.string.strip() for s in soup.find_all('script')
if s.string is not None
and s.string.strip().startswith("window.__REDIAL_PROPS__")]
if len(script) != 1:
print("Cannot find window.__REDIAL_PROPS__ script in which we are \
supposed to retrieve the data json", file=sys.stderr)
sys.exit(1)
lbcjsonstart = script[0].find('[')
lbcjson = json.loads(script[0][lbcjsonstart:])
ads = [obj["data"]["ads"] for obj in lbcjson
if type(obj) == dict and "data" in obj
and "ads" in obj["data"]]
if len(ads) != 1:
print("Cannot find the ads section in flux state")
sys.exit(1)
print(json.dumps(ads[0]))
signal(SIGPIPE, SIG_DFL)
sys.exit(0)