0

I have been trying to figure out how to get the "form:" value from a html tag that looks like:

window.__webpack_public_path__='https://renderer-assets.helloWorld.com/';
window.__webpack_nonce__='ca0aa826f043cfc50cc24f6ae5a2fb4a';
window.rendererAssets='["https://renderer-assets.helloWorld.com/vendors~attachment~form-container.0ca60599ecb1b55e02bf.js","https://renderer-assets.helloWorld.com/vendors~libphonenumber~submission.7a28f3a3fe6660429a73.js","https://renderer-assets.helloWorld.com/country-data.62e9eca111db492e793d.js","https://renderer-assets.helloWorld.com/form-container.c34f13ff7b2a95addd81.js","https://renderer-assets.helloWorld.com/renderer.c8aaed3fb2c5d344f80d.js","https://renderer-assets.helloWorld.com/submission.a2f19d1069d330fd0866.js","https://renderer-assets.helloWorld.com/vendors~form-container.9853dbb220cd33f30c2f.js"]';
window.rendererData= {
    scriptSrc: 'https://renderer-assets.helloworld.com/renderer.c8aaed3fb2c5d344f80d.js',
    rootDomNode: 'root',
    form: {
        "id":"Z3PvTW",
        "title":"TESTING",
        "theme": {
            "id":"xwizbR",
            "font":"Oswald",
            "name":"Plain Blue (copy)",
            "colors": {
                "question": "#3D3D3D", "answer": "#000000", "button": "#000000", "background": "#FFFFFF"
            }
            ,
            "has_transparent_button":false,
            "visibility":"private"
        }
        ,
        "workspace": {
            "href": "https:\u002F\u002Fapi.helloWorld.com\u002Fworkspaces\u002FnutqqY"
        }
        ,
        "settings": {
            "is_public":true,
            "is_trial":false,
            "language":"en",
            "progress_bar":"proportion",
            "show_progress_bar":true,
            "show_helloWorld_branding":true,
            "meta": {
                "allow_indexing": false
            }
        }
        ,
        "welcome_screens":[ {
            "ref":"a13820db-af60-40eb-823d-86cf0f20299b",
            "title":"TESTING VALUES",
            "properties": {
                "show_button": true, "button_text": "Start"
            }
        }
        ],
        "thankyou_screens":[ {
            "ref":"default_tys",
            "title":"Done! Your information was sent perfectly.",
            "properties": {
                "show_button": false, "share_icons": false
            }
        }
        ],
        "fields":[ {
            "id":"kxWycKljdtBq",
            "title":"FIRST NAME",
            "ref":"27f403f7-8c5b-4e18-b19d-1501e8f137ee",
            "validations": {
                "required": true
            }
            ,
            "type":"short_text"
        },
        {
            "id":"WEXCnZ7EAFjN",
            "title":"LAST NAME",
            "ref":"a6bf6d83-ee37-4870-b6c5-779822290cde",
            "validations": {
                "required": true
            }
            ,
            "type":"short_text"
        }

        ],
        "_links": {
            "display": "https:\u002F\u002Fautosnkr.helloWorld.com\u002Fto\u002FZ3PvTW"
        }
    }
    ,
    trackingInfo: {
        "segmentKey": "9at6spGDYXelHDdz4r0cP73b3wV1f0ri", "accountId": 12587347, "accountLimitName": "Essentials", "userId": 12586030
    }

My point here is to be able to get the whole form: value into a json.loads where I can later on modify it the way I want to do but before that I need to be able to get the form: value and what I have tried to do is following:

regexTest = re.compile(r'form:\((.*?)\);', re.DOTALL)
data = regexTest.findall(response.text)

which just returned []

My question is, how am I able to get the whole form: json value into a getAllForm = json.loads(...)?

PythonNewbie
  • 1,031
  • 1
  • 15
  • 33

1 Answers1

1
match = re.search(r"form: ({(\s+.*){1,}\})", response.text).group(1)
print(match)

Output:

{
        "id":"Z3PvTW",
        "title":"TESTING",
        "theme": {
            "id":"xwizbR",
            "font":"Oswald",
            "name":"Plain Blue (copy)",
            "colors": {
                "question": "#3D3D3D", "answer": "#000000", "button": "#000000", "background": "#FFFFFF"
            }
            ,
            "has_transparent_button":false,
            "visibility":"private"
        }
        ,
        "workspace": {
            "href": "https://api.helloWorld.com/workspaces/nutqqY"
        }
        ,
        "settings": {
            "is_public":true,
            "is_trial":false,
            "language":"en",
            "progress_bar":"proportion",
            "show_progress_bar":true,
            "show_helloWorld_branding":true,
            "meta": {
                "allow_indexing": false
            }
        }
        ,
        "welcome_screens":[ {
            "ref":"a13820db-af60-40eb-823d-86cf0f20299b",
            "title":"TESTING VALUES",
            "properties": {
                "show_button": true, "button_text": "Start"
            }
        }
        ],
        "thankyou_screens":[ {
            "ref":"default_tys",
            "title":"Done! Your information was sent perfectly.",
            "properties": {
                "show_button": false, "share_icons": false
            }
        }
        ],
        "fields":[ {
            "id":"kxWycKljdtBq",
            "title":"FIRST NAME",
            "ref":"27f403f7-8c5b-4e18-b19d-1501e8f137ee",
            "validations": {
                "required": true
            }
            ,
            "type":"short_text"
        },
        {
            "id":"WEXCnZ7EAFjN",
            "title":"LAST NAME",
            "ref":"a6bf6d83-ee37-4870-b6c5-779822290cde",
            "validations": {
                "required": true
            }
            ,
            "type":"short_text"
        }

        ],
        "_links": {
            "display": "https://autosnkr.helloWorld.com/to/Z3PvTW"
        }
    }
    ,
    trackingInfo: {
        "segmentKey": "9at6spGDYXelHDdz4r0cP73b3wV1f0ri", "accountId": 12587347, "accountLimitName": "Essentials", "userId": 12586030
    }

Now regarding loading your JSONP dict into valid JSON dict.

Check that key which is trackingInfo, it's actually missing trackingInfo to be as "trackingInfo". So you need to quote it, Since this will be count as a duplicate. Please check that answer