python实现长截图_firefox插件screengrap +python autoit+selenium实现整个网页的长截图功能...

本文介绍了一种使用Python、Firefox插件screengrap、autoit库和selenium实现整个网页长截图的方法。通过示例代码详细展示了如何激活浏览器窗口,触发截图并保存图片。
摘要由CSDN通过智能技术生成

笔记:本人用的是python3.6.6 32位的版本,安装成功了pyautoit库及autoit库

本人的firefox版本为45.0可以安装firebug、fire path、及screengrap插件

直接代码如下:

import autoit

import unittest

import time

import sys

from datetime import datetime

from actions import Actions

from selenium import webdriver

from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support.wait import WebDriverWait

from selenium.webdriver import ActionChains

from selenium.webdriver.common.by import By

from selenium.webdriver.support import expected_conditions as EC

sys.path.append(‘D:\jftest1_CG\test1’)

class Test_Newyyy_pctz_shfk (unittest.TestCase):

def test_pcLogin(self):

fp = webdriver.FirefoxProfile(r"C:\Users\mhf\AppData\Roaming\Mozilla\Firefox\Profiles\cv6txwo2.default")

driver = webdriver.Firefox(fp)

# driver = webdriver.Firefox ()

driver.get (“https://www.csdn.net/”)

WebDriverWait (driver, 10).until (EC.presence_of_element_located ((By.LINK_TEXT, ‘博客’)))

#获取浏览器窗口

autoit.win_activate(‘CSDN-专业IT技术社区 - Mozilla Firefox’)

print(“1111”)

autoit.send(’{LCTRL down}’+’{LSHIFT down}’+’{! down}’)

# autoit.send(’{LCTRL down}’ + ‘{LALT down}’ + ‘{a down}’)

# driver.find_element_by_id(‘login’).send_keys(Keys.CONTROL + Keys.SHIFT + ‘!’)

time.sleep(2)

autoit.win_wait(‘截取的图片另存为…’)

print(“2222”)

autoit.control_focus(‘截取的图片另存为…’,‘1001’)

print(“3333”)

autoit.win_wait("[Class:#32770]",10)

t = datetime.now().strftime(’%Y%m%d%H%M%S’)

name=‘百度首页’+t

autoit.control_set_text(‘截取的图片另存为…’,‘Edit1’,name)

autoit.control_click(‘截取的图片另存为…’,‘Button2’)

driver.close()

if name == ‘main’:

unittest.main ()

可以实现整个网页的截图

官方的例子,也可参考:

import autoit

import time

autoit.run(“notepad.exe”)

autoit.win_wait_active("[CLASS:Notepad]", 3)

autoit.control_send("[CLASS:Notepad]", “Edit1”, “hello world{!}”)

autoit.win_close("[CLASS:Notepad]")

time.sleep(100)

autoit.control_click("[Class:#32770]", “Button2”)

time.sleep(100)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值