python - 我可以使用 selenium webdriver 读取浏览器 url 吗?

标签 python selenium beautifulsoup selenium-webdriver

我正在使用 python2.7 和 beautiful Soup4 和 Selenium webdriver。现在在我的 webautomation 脚本中,我将打开链接或 URL 并进入主页。现在我需要点击一些 anchor Labels 来浏览其他页面。我一直这样做到现在。现在,当我要转到一个新页面时,我需要从浏览器获取新的 URL,因为我需要将它传递给 Beautiful Soup4 以进行网页抓取。所以现在我关心的是如何以动态方式获取此类 URL?

如有请指教!

最佳答案

您在驱动程序上获得 current_url 属性:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print(browser.current_url)

关于python - 我可以使用 selenium webdriver 读取浏览器 url 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14166572/

相关文章:

python - 美汤找不到标签

python - 在 OS X 上安装 pip

Python django-admin startproject mysite

python - worker : Warm shutdown (MainProcess) after task started

selenium - TestNG中BeforeClass和BeforeTest的区别

java - 如何为 Selenium webdriver assert 连接嵌套的 xpath?即连续标签和单独的按钮

python - 如何打印并显示网页抓取的所有结果?

python - 创建没有 NaN 的 pandas MultiIndex Dataframe

java - Play 2.5 和 Fluentlenium : how to turn HtmlUnit warnings off

python - 将excel中的数据粘贴到网站,点击 "track"