Kha*_*if 3 python selenium python-3.x selenium-chromedriver selenium-webdriver
我正在尝试使用 selenium 和 chromedriver 获取全页屏幕截图,但我得到的是半屏幕截图。我尝试过其他方法,但到目前为止只有这个有效,而且只需要半页屏幕截图。
任何人都可以使用另一个技巧来解决这个问题,也可以附加输出结果。
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.headless = True
driver = webdriver.Chrome(options=options)
URL = "http://stevens.ekkel.ai"
driver.get(URL)
S = lambda X: driver.execute_script('return document.body.parentNode.scroll'+X)
driver.set_window_size(S('Width'),S('Height')) # May need manual adjustment
driver.find_element_by_tag_name('body').screenshot('web_screenshot.png')
driver.quit()
Run Code Online (Sandbox Code Playgroud)
我正在使用 PyPI 包:Selenium-Screenshot
您可以使用命令安装它 -pip install Selenium-Screenshot
该包的详细信息可以在此处找到: https: //pypi.org/project/Selenium-Screenshot/
分享一个关于如何使用此包进行全页屏幕截图的示例补丁:
from Screenshot import Screenshot_Clipping
#Saving screenshot
ob=Screenshot_Clipping.Screenshot()
img=ob.full_Screenshot(driver,save_path=r'D:/OneDrive -Libin/Python/Sel_python/Pytest/Screenshots',image_name="Screenshot1.png")
driver.close()
driver.quit()
Run Code Online (Sandbox Code Playgroud)
检查屏幕截图以供参考:
归档时间: |
|
查看次数: |
9812 次 |
最近记录: |