python - 使用Selenium截图时的"TypeError: get_screenshot_as_file() takes exactly 2 arguments (1 given)"

标签 python python-2.7 selenium selenium-webdriver

我正在尝试使用 Selenium webdriver 截取给定链接的屏幕截图,但遇到以下错误

browser.get_screenshot_as_file()
TypeError: get_screenshot_as_file() takes exactly 2 arguments (1 given)

我正在使用的代码块是

link = comment.permalink
browser = webdriver.Firefox()
browser.get(link)
browser.get_screenshot_as_file()
browser.quit()

最佳答案

您需要为其指定一个用于保存屏幕截图的文件名:

browser.get_screenshot_as_file('path/to/the/file.jpg')

关于python - 使用Selenium截图时的"TypeError: get_screenshot_as_file() takes exactly 2 arguments (1 given)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23174943/

相关文章:

python - Bokeh 中的多线时间序列图

python - 在 MongoDB 中插入指定 _id 字段的变量

linux - 用于检查服务是否正在运行的 Python 代码。?

python - 为什么我未 pickle 的顺序与 pickle 时的顺序不同?

java - 如果该文件每天都在增加,如何在 selenium Java 中完全验证文件下载

python - 字符串开头只允许字母字符?

Python csv.writer 添加不需要的字符

python - 按Python字典中的嵌套字典排序

python - 无法找到带有 selenium 的按钮 'ctl00'

python - PhantomJS 放在路径中,可以在终端执行,但在 Python 中出现 PATH 错误