我做了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-&co=aHR0cHM6Ly93d3cuZ29vZ2xlLmNvbTo0NDM.&hl=en&v=r20171206132803&size=normal&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;
基本上我试图在src中获取链接,以提取验证码密钥k = ...
感谢。
答案 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])