Issue
I have code like this:
if request.method == 'POST':
form = SearchForm(request.POST)
if form.is_valid():
text = form['look'].value()
chrome_options = Options()
chrome_options.add_experimental_option(
"excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option(
'useAutomationExtension', False)
chrome_options.add_experimental_option("prefs", {
"download.prompt_for_download": False,
"safebrowsing.enabled": True
})
driver = webdriver.Chrome(
ChromeDriverManager().install(), options=chrome_options)
driver.maximize_window()
driver.get(text)
...
Then I get a URL like this: https://lovepik.com/image-610179440/cartoon-mothers-day-vector-material.html
But I want the returned result to only get the ID of 610179440, what should I do?
Solution
Use Below code
url = driver.current_url
id = url.split("image-", 1)[1].split("/")[0]
print(id)
Answered By - Ketan Pardeshi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.