我必须拍摄一个元素的截图,并将其保存为pdf格式。现在我只截图,然后保存它,但我仍然不知道如何将它转换成pdf
我如何做到这一点?这是迄今为止的代码:
#save screenshot
sleep(4)
constancia = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/table[2]')))
constancia_screenshot = constancia.screenshot_as_png
with open('constancia.png', 'wb') as f:
f.write(constancia_screenshot)
如图所示,使用pillow和io模块,pillow将字节转换为文件,然后使用pillow进行转换
https://pypi.org/project/Pillow/
看一下从png到pdf的转换
这里有一个这样的图书馆: https://pypi.org/project/img2pdf/
相关问题 更多 >
编程相关推荐