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&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
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&key=874a4c1e464f7d8fb61465c6fdb63a69aeb536fa490a66f66d37395f4cfce98e"}</body>'
substr = str[str.find("{\"url\":")+7 : str.find("}")]
print(substr)
Output:
"https:\/\/shop.website.com\/cart\/12260378345553:1?step=payment_method&key=874a4c1e464f7d8fb61465c6fdb63a69aeb536fa490a66f66d37395f4cfce98e"
default