我正在嘗試使用 selenium 獲取當前 url。這是我的代碼:
#landing on page
driver.get("http://web.archive.org/web/20200922013649/https://www.shadesofstone.com/hardscape/flagstones-more/landscape-galore.html")
#get current url
main_link = driver.current_url
print(main_link)
但我只得到這個:
https://www.shadesofstone.com/hardscape/flagstones-more/landscape-galore.html
而不是這個
http://web.archive.org/web/20200922013649/https://www.shadesofstone.com/hardscape/flagstones-more/landscape-galore.html
這里出了什么問題?
uj5u.com熱心網友回復:
看起來像一個錯誤driver.current_url。
這是您可以使用的解決方法:driver.execute_script("return document.location.href;")
driver.get("http://web.archive.org/web/20200922013649/https://www.shadesofstone.com/hardscape/flagstones-more/landscape-galore.html")
main_link = driver.execute_script("return document.location.href;")
print(main_link)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/509935.html
上一篇:使用python從多個Highcharts圖表中抓取資料
下一篇:已解決:python:selenium.common.exceptions.InvalidArgumentException:訊息:無效引數:無效定位器
