0

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!

demouser123
3,5325 gold badges30 silver badges41 bronze badges
asked May 28, 2018 at 1:34

1 Answer 1

2

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("}")]
print(substr)

Output:

"https:\/\/shop.website.com\/cart\/12260378345553:1?step=payment_method&amp;key=874a4c1e464f7d8fb61465c6fdb63a69aeb536fa490a66f66d37395f4cfce98e"
answered May 28, 2018 at 4:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.