2015-07-10 66 views
2

或者可能「破解」webbrowserSelenium的實際庫代碼來執行此操作?我在看當前的文檔,並沒有看到這是可能的,但也許你可以調整實際的庫代碼並插入此功能?是否可以使用網頁瀏覽器或Selenium在瀏覽器中抓取當前URL

不幸的是,硒下列方法是行不通的 - 它只返回原來的URL:

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 
+1

這可能會有幫助。 http://stackoverflow.com/questions/16242340/selenium-get-current-url-after-loading-a-page – bob0the0mighty

回答

2

蟒蛇web瀏覽器模塊調用外部的過程,不同的是依賴於平臺,甚至是環境變量平臺。所以我一般會說「不」。

3

不,但如果你正在尋找一個模塊,讓你更好地控制瀏覽器看看硒webdriver。

在硒的功能是driver.current_url

爲bob0the0mighty的鏈接顯示,你需要有一個循環,等待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): if(currenturl != initialurl): print currenturl break

+1

這只是返回我調用的初始URL,而不是重定向 – AdjunctProfessorFalcon

+0

看到我的編輯上面 – rubes114