Selenium - Python - 获取验证码 Url(从生成的链接)

发布于 2024-12-14 04:31:30 字数 314 浏览 4 评论 0原文

Python - Selenium / urllib2

我需要获取下载验证码图像的 url。

图像代码:img src =“ generatedlink”

我需要将这个“ generatedlink”解析为变量

variable =“ generatedlink”

有没有办法用selenium或urllib2得到这个?

(我可以使用 urllib.retrieve (手动)将生成的链接传输到 local.jpg 文件中,但我无法执行第一步(自动获取链接并将其放入变量中)。)

谢谢您提供的任何信息

Python - Selenium / urllib2

I need to get the url to download a captcha image.

Image code : img src = "generatedlink"

I need to parse this "generatedlink" into a variable

variable = "generatedlink"

Is there a way to get this with selenium or urllib2 ?

( I am able to transfer my generated link into local.jpg file with urllib.retrieve (manually) but i cant do the first step ( get the link automatically and put it into variable) .)

Thank you for any info

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

焚却相思 2024-12-21 04:31:30

如果您使用的是 selenium 2,则可以这样做,此示例通过 xpath 引用它:

wd = self.webdriver
src = wd.find_element_by_xpath("//div[@id='recaptcha_image']/img").get_attribute('src')

If you are using selenium 2 this is how you would do it, this example references it by xpath:

wd = self.webdriver
src = wd.find_element_by_xpath("//div[@id='recaptcha_image']/img").get_attribute('src')
如梦 2024-12-21 04:31:30

如果您使用 Python,则应执行以下操作:

# Assuming "sel" is your selenium instance
img_src = sel.get_attribute('css=img#myimage@src')
# Or, if you subclassed SeleniumLibrary
img_src = self._selenium.get_attribute('css=img#myimage@src')

If you are working with Python, the following should do:

# Assuming "sel" is your selenium instance
img_src = sel.get_attribute('css=img#myimage@src')
# Or, if you subclassed SeleniumLibrary
img_src = self._selenium.get_attribute('css=img#myimage@src')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文