我有這樣的代碼:
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)
...
然后我得到一個這樣的 URL: https ://lovepik.com/image-610179440/cartoon-mothers-day-vector-material.html
但是我希望回傳的結果只能得到610179440的ID,怎么辦?
uj5u.com熱心網友回復:
使用下面的代碼
url = driver.current_url
id = url.split("image-", 1)[1].split("/")[0]
print(id)
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/497996.html
