类型字节与 base64 类型错误有问题:需要类似字节的对象,而不是'str'



我的类型有问题,如果你能帮助我,我将非常高兴。我正在使用下载captcha

captcha = self.chrome_driver.driver.find_element_by_xpath(captcha_xpath).screenshot_as_png

根据文档:将当前元素的屏幕截图保存为二进制数据然后我想把它发送到两个captcha函数normal(captcha, caseSensitive=True),根据文档,它会拍摄图像或base64。所以当我运行该功能时,我会得到错误

TypeError:需要类似字节的对象,而不是'strcaptcha的类型是<类"字节">

如何将captcha转换为base64或image以使其工作。

为什么不按照这里的方法列表简单地用.screenshot_as_base64()替换.screeshot_as_png呢。

get_screenshot_as_base64()
Gets the screenshot of the current window as a base64 encoded string
which is useful in embedded images in HTML.
Usage:  driver.get_screenshot_as_base64()

您可能面临的更大问题是,您正在搜索一个元素,而这两种方法都是为了保存整个屏幕。我建议除了保存为base64之外,如果你不想保存整个屏幕,你还可以阅读Stack上关于这个主题的许多其他问题之一。

最新更新