我正在try 获得当前的网址使用selenium.以下是我的代码:

#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)

Python相关问答推荐

如何将双框框列中的成对变成两个新列

如何删除索引过go 的lexsort深度可能会影响性能?' &>

如何在Windows上用Python提取名称中带有逗号的文件?

通过Selenium从页面获取所有H2元素

如何获取TFIDF Transformer中的值?

我如何使法国在 map 中完全透明的代码?

Python,Fitting into a System of Equations

如何在Python数据框架中加速序列的符号化

海上重叠直方图

以逻辑方式获取自己的pyproject.toml依赖项

Python协议不兼容警告

Python:从目录内的文件导入目录

如何提高Pandas DataFrame中随机列 Select 和分配的效率?

如何从数据框列中提取特定部分并将该值填充到其他列中?

TypeError:';Locator';对象无法在PlayWriter中使用.first()调用

在任何要保留的字段中添加引号的文件,就像在Pandas 中一样

#将多条一维曲线计算成其二维数组(图像)表示

如何在不不断遇到ChromeDriver版本错误的情况下使用Selify?

如何通过函数的强式路径动态导入函数?

Pandas查找给定时间戳之前的最后一个值