在recaptcha iframe,selenium,python中获取src内容

时间:2017-12-12 03:55:11

标签: python selenium recaptcha

我做了driver.get(" https://www.google.com/recaptcha/api2/demo")

我想在recaptcha iframe中获取src。这是元素



<iframe src="https://www.google.com/recaptcha/api2/anchor?k=6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-&amp;co=aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbTo0NDM.&amp;hl=en&amp;v=r20171206132803&amp;size=normal&amp;cb=jsergcmr02x3" width="304" height="78" role="presentation" frameborder="0" scrolling="no" sandbox="allow-forms allow-popups allow-same-origin allow-scripts allow-top-navigation allow-modals allow-popups-to-escape-sandbox"></iframe>
&#13;
&#13;
&#13;

基本上我试图在src中获取链接,以提取验证码密钥k = ...

感谢。

1 个答案:

答案 0 :(得分:0)

如果您只想从src中提取验证码密钥k=...,可以使用以下代码行:

my_src = driver.find_element_by_xpath("//iframe[contains(@src,'https://www.google.com/recaptcha/api2/anchor')]").get_attribute("src")
parts = my_src.split("?k=")
print(parts[1])