I'm trying to copy a certain string of a website's source code using selenium.

This is the page's source code:

<body data-gr-c-s-loaded="true">{"url":"https:\/\/shop.website.com\/cart\/12260378345553:1?step=payment_method&amp;key=874a4c1e464f7d8fb61465c6fdb63a69aeb536fa490a66f66d37395f4cfce98e"}</body>

I would like selenium to grab the link seen after the "url": part. Any help would be appreciated!

1 Answer 1


You want to find the string between {"url": and }. Use str.Find to find the position of the substring you need.

str = '<body data-gr-c-s-loaded="true">{"url":"https:\/\/shop.website.com\/cart\/12260378345553:1?step=payment_method&amp;key=874a4c1e464f7d8fb61465c6fdb63a69aeb536fa490a66f66d37395f4cfce98e"}</body>'
substr = str[str.find("{\"url\":")+7 : str.find("}")]



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.