Python 是否可以使用webbrowser或Selenium在浏览器中获取当前URL
或者可能“黑客”实际的库代码,或者这样做?我查看了当前的文档,没有发现这是可能的,但是您可以调整实际的库代码并插入此功能吗 不幸的是,使用Selenium的以下方法不起作用-它只返回原始URL:Python 是否可以使用webbrowser或Selenium在浏览器中获取当前URL,python,python-2.7,selenium,python-webbrowser,Python,Python 2.7,Selenium,Python Webbrowser,或者可能“黑客”实际的库代码,或者这样做?我查看了当前的文档,没有发现这是可能的,但是您可以调整实际的库代码并插入此功能吗 不幸的是,使用Selenium的以下方法不起作用-它只返回原始URL: import selenium from selenium import webdriver driver = webdriver.Chrome() driver.get("https://api.instagram.com/oauth/authorize/?client_id=cb0096f08a3
import selenium
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://api.instagram.com/oauth/authorize/?client_id=cb0096f08a387355f&redirect_uri=http://pythondev.instadev.com/instagramredirect.html&response_type=code")
print driver.current_url
pythonwebbrowser模块启动一个外部进程,该进程根据平台甚至平台上的环境变量而有所不同。所以我通常会说“不”。不,但是如果您正在寻找一个能够更好地控制浏览器的模块,请查看selenium webdriver 在selenium中,函数是 正如Bob00Minty的链接所示,您需要有一个等待url更改的循环。尝试以下方法:
initialurl=”https://api.instagram.com/oauth/authorize/client_id=cb0096f08a387355f&redirect_uri=http://pythondev.instadev.com/instagramredirect.html&response_type=code“
currenturl=”https://api.instagram.com/oauth/authorize/?client_id=cb0096f08a387355f&redirect_uri=http://pythondev.instadev.com/instagramredirect.html&response_type=code“
while(true):
如果(currenturl!=初始URL):
打印当前URL
中断只返回我调用的初始URL的
,而不是重定向,这可能会有所帮助。