我正在尝试使用 Python 中的 Selenium Webdriver 从 URL 下载图像。该站点受登录页面保护,因此不能仅使用请求保存 URL 内容。登录后我可以从站点获取文本,但我不知道如何保存图像。
登录该站点后,我可以执行此操作,browser.save_screenshot(filename + '.png')但该图像与原始图像的大小不正确。
我现在拥有的代码是这样的:
browser = webdriver.Chrome('../chromedriver')
browser.get('www.example.com/login')
# send username and password, click submit
browser.get('www.example.com/123')
html = browser.page_source
printData(html)
# this url is an image file
browser.get('www.example.com/get_photo.php?id=123')
browser.save_screenshot(filename + '.png')
Run Code Online (Sandbox Code Playgroud)
理想情况下,我想用类似的save_screenshot()东西替换
with open(filename + '.jpeg', 'w') as img:
img.write(browser.download_current_image())
Run Code Online (Sandbox Code Playgroud)
甚至像这样的东西,与弹出菜单交互
browser.right_click()
browser.down_arrow_key()
browser.return_key()
Run Code Online (Sandbox Code Playgroud)
或模拟按键
browser.command_key()
browser.s_key()
Run Code Online (Sandbox Code Playgroud)
这个问题给出了我想要的答案,但不适用于 Python。如果有办法在 Python 中执行该问题中建议的任何操作(除了截屏),那将是一个很好的解决方案。
我有一个字符串“abcdefg”。我想匹配任何相当于删除末尾字符的子字符串。因此,除了匹配“abcdefg”之外,字符串“abc”、“a”和“abcd”也应该全部匹配。
使用a|ab|abc|abcd|abcde|abcdef|abcdefg会起作用,但它本质上只是一个字符串列表。
有没有更节省空间的方法来做到这一点?
此外,我无法使用前瞻/后瞻,因为 Go 不支持它们。