当前位置: 首页 > news >正文

使用Selenium的WebDriver进行长截图

from selenium import webdriver
from PIL import Image
from io import BytesIO
# 创建浏览器驱动
driver = webdriver.Chrome()# 打开网页
driver.get("https://www.douban.com/")  # 替换为您要截图的网页URL
def get_long_shot(driver,table_element):# 获取页面的初始高度和宽度# 获取表格元素的位置和大小table_location = table_element.locationtable_size = table_element.size# 创建一个与表格相同大小的窗口,并移动到表格位置driver.set_window_size(table_size["width"], table_size["height"])driver.set_window_position(table_location["x"], table_location["y"])# 初始化一个空白长截图long_screenshot = Image.new('RGB', (table_size["width"], table_size["height"]))# 向下滚动以截取表格的所有内容scroll_position = 0while scroll_position < table_size["height"]:driver.execute_script(f"window.scrollTo(0, {scroll_position})")screenshot = Image.open(BytesIO(driver.get_screenshot_as_png()))long_screenshot.paste(screenshot, (0, scroll_position))scroll_position += screenshot.height# 向右滚动以截取表格的所有内容scroll_position = 0while scroll_position < table_size["width"]:driver.execute_script(f"window.scrollTo({scroll_position}, 0)")screenshot = Image.open(BytesIO(driver.get_screenshot_as_png()))long_screenshot.paste(screenshot, (scroll_position, 0))scroll_position += screenshot.width# 保存长截图long_screenshot.save("table_long_screenshot.png")
http://www.lryc.cn/news/194827.html

相关文章:

  • python+大数据校园卡数据分析 计算机竞赛
  • 【机器学习】sklearn降维算法PCA
  • 华为云云耀云服务器L实例评测|企业项目最佳实践之评测用例(五)
  • Xcode升级到15.0 解决DT_TOOLCHAIN_DIR问题
  • 小谈设计模式(29)—访问者模式
  • 【25】c++设计模式——>责任链模式
  • GlobalTransactional
  • Android Studio运行kotlin项目,一直Read timed out
  • Excel 的单元格内容和单元格格式
  • 4大软件测试策略的特点和区别(单元测试、集成测试、确认测试和系统测试)
  • armbian 安装mysql
  • Ubuntu22常用软件
  • 【CFD小工坊】浅水模型的边界条件
  • 电力物联网关智能通讯管理机-安科瑞黄安南
  • 用Flask构建一个AI翻译服务
  • 微信小程序引入阿里巴巴iconfont图标并使用
  • mysql面试题49:MySQL中不同text数据类型的最大长度
  • 从虚拟电厂在上海的实践探索看企业微电网数字化的意义
  • 创建并初始化线程池
  • 【LeetCode热题100】--136.只出现一次的数字
  • Java idea查看自定义注解的调用地方
  • ReLU激活函数
  • 【Android】adjustViewBounds 的理解和使用
  • Redis知识补充
  • IIS 部署.NetCore,最细步骤
  • 4.查询用户的累计消费金额及VIP等级
  • 解决MySQL错误-this is incompatible with sql_mode=only_full_group_by
  • UDP通信-广播、组播
  • 10-bean创建流程1一finishBeanFactoryInitialization(ConfigurableListableBeanFactory
  • 专题三:穷举、暴搜、深搜、回溯、剪枝【递归、搜索、回溯】