Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用selenium获取当前页面url_Python_Python 3.x_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

Python 使用selenium获取当前页面url

Python 使用selenium获取当前页面url,python,python-3.x,selenium,selenium-webdriver,selenium-chromedriver,Python,Python 3.x,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在使用selenium打开一个页面。我正在尝试获取当前打开的页面url,但似乎无法获取 from selenium import webdriver from selenium.webdriver.chrome.options import Options import getpass vid = 'https://openload.co/f/KgNvMOs9fws/C__Program_Files_Python36_placeholder.mp4' chrome_options = we

我正在使用selenium打开一个页面。我正在尝试获取当前打开的页面url,但似乎无法获取

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import getpass

vid = 'https://openload.co/f/KgNvMOs9fws/C__Program_Files_Python36_placeholder.mp4'
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('load-extension=C:/Users/'+getpass.getuser()+'/AppData/Local/Google/Chrome/User Data/Default/Extensions/leallakffbiflfgpmamdgcojddnbfdgo/1.1.8_0')
driver = webdriver.Chrome(chrome_options=chrome_options)
print('Start')
driver.get(vid)
print('Middle')
urlpage = driver.current_url
print(urlpage)
print('End')

我有一个chrome扩展,可以修改视频的url。我试图抓取修改后的页面url,但没有必要添加时间延迟,因为我无法首先抓取视频页面的url,因为某些原因。和
驱动程序。当前的\u url
不起作用。

如果您在
.get()
上遇到问题,则您必须使用chromedriverChrome browser的错误组合

我建议从更新到chromedriver 2.36或上面的

并通过打开以下URL确保您已更新到当前的Chrome Build 65:

chrome://settings/help

如果无法更新到当前版本,请尝试以下操作:

from selenium import webdriver

ChromeOptions = webdriver.ChromeOptions()
ChromeOptions.add_argument('--disable-browser-side-navigation')
driver = webdriver.Chrome('your/path/to/chromedriver.exe', chrome_options=ChromeOptions)

有关这个问题的原始答案,请参阅上面脚本的输出是什么?它怎么会“不工作”?没有输出,它只是无限期地挂起,直到程序结束。它导航到目标网页了吗?是的,它打开了我输入的url,但永远挂在
驱动程序上。get(vid)
那么,驱动程序就没有问题了。当前的url,它永远不会走那么远。问题在于变量“vid”中的路径。你能在同一个浏览器中手动打开它吗?我已经完成了这项工作,并且得到了相同的结果,添加了一条带有结果的注释。因此,它现在通过了
.get()
?不,它在更改后不会返回页面url。如果我禁用更改页面url的扩展,它会工作,但启用扩展后,它会返回不工作状态。这没关系,只是我觉得它应该返回当前实例中页面的url。通过“返回url”,您的意思是它应该通过
.get()
?或者您实际上是在访问
当前的\u url
?如果您仍然挂在
.get()
上,那么页面是正在加载还是似乎将永远加载?勾选左上角的圆圈。