我正在尝试使用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
这里出了什么问题?
看起来像是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)