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

2024-03-28 23:12:39 发布

您现在位置:Python中文网/ 问答频道 /正文

是的驱动程序。获取(“https://www.google.com/recaptcha/api2/demo”)

我想让src进入recaptcha iframe。这是eleme

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

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

谢谢。在


Tags: httpssrccomdemowwwgoogle驱动程序recaptcha
1条回答
网友
1楼 · 发布于 2024-03-28 23:12:39

如果您只想从src提取captcha密钥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])

相关问题 更多 >