F
F
fleksss_pod_papicha2019-10-31 20:24:58
Python
fleksss_pod_papicha, 2019-10-31 20:24:58

How to pull this in python?

I made a page parser, what I needed was in the script tag, I pulled out the content of this tag

<script>
 window.settings ={"feedPrefix":"dnevnik","rootUrl":"https://kundelik.kz","apiUrl":"https://kundelik.kz/api","environmentPrefix":"kz"};
 </script>

how to pull this dictionary? I used the BS and Requests libraries,
or is it possible to somehow convert this script to normal?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
asd111, 2019-10-31
@asd111

import re
import json
string ='''<script>
 window.settings ={"feedPrefix":"dnevnik","rootUrl":"https://kundelik.kz","apiUrl":"https://kundelik.kz/api","environmentPrefix":"kz"};
 </script>'''
r = re.search("window.settings =(.*);", string)
if r:
    dic = json.loads(r.groups()[0])
    print(dic["feedPrefix"])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question