单击链接后查找 URL [英] Find URL after clicking a link

查看:32
本文介绍了单击链接后查找 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在点击元素后使用 selenium 查找当前 url.我有这个网站:http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622

How can i use selenium to find the current url after clicking an element. I have this website: http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622

我有代码(假设所有相关库都已导入)

I have the code(assuming all related libraries are imported)

def get_detail(x):
    dic = {}
    driver = webdriver.PhantomJS(path)
    driver.get(x)
    driver.find_element_by_id('ctl00_ctl00_MainContent_hypPrimaryURL').click()
    return driver.current_url
print get_detail('http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622')

我运行了代码,它只返回原始网址,即 http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622

I ran the code and it only return the original url which is http://www.runningintheusa.com/Classic/View.aspx?RaceID=5622

我如何在点击网站上的 Race Website 链接后找到网址,该链接是 http://flagstaffbigs.org/dave-mckay-run.htm

How can i find the url after clicking the Race Website link on the site which is http://flagstaffbigs.org/dave-mckay-run.htm

推荐答案

是不是因为打开了一个新标签页,这将选择活动的最新标签页.

Is it because a new tab is opening, this will select the active newest tab.

driver.switch_to_window(driver.window_handles[-1])
return driver.current_url;

这篇关于单击链接后查找 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆