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

笔记:本人用的是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’)
1111111
#最后再点击一次shift键 释放长按shift ,以免后续操作不方便,点哪都觉得不好使,解铃还须系铃人(autoit)。。。
autoit.send (’{LCTRL}’ + ‘{LSHIFT}’)
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)

笔记:python的模块pywin32 可以释放按键
import win32api
import win32con
win32api.keybd_event (17, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键ctrl
win32api.keybd_event (16, 0, win32con.KEYEVENTF_KEYUP, 0) # 释放按键shift

附:常用模拟键的键值对照表

键盘键与虚拟键码对照表

字母和数字键     数字小键盘的键       功能键         其它键
      键   键码     键   键码       键   键码     键      键码
      A   65      0   96        F1   112     Backspace    8
      B   66      1   97        F2   113     Tab        9
      C   67 2   98        F3   114     Clear       12
      D   68      3   99 F4   115     Enter       13
      E   69       4   100 F5   116     Shift      16
      F   70       5   101 F6   117     Control      17
      G   71       6   102       F7   118      Alt        18
      H   72       7   103       F8   119     Caps Lock     20
      I   73       8   104       F9   120      Esc        27
      J   74       9   105       F10  121     Spacebar    32
      K   75 *   106       F11  122     Page Up     33
      L   76 +   107       F12  123     Page Down    34
      M   77       Enter 108       –   –     End        35
      N   78 -   109       –   –       Home      36
      O   79       .   110       –   –       Left Arrow    37
      P   80       /    111       –   –      Up Arrow     38
      Q   81       –   –       –   –       Right Arrow    39
      R   82       –   –       –   –       Down Arrow    40
      S   83       –   –       –   –       Insert      45
      T   84       –   –       –   –       Delete      46
      U   85       –   –       –   –       Help       47
      V   86       –   –       –   –       Num Lock     144
      W   87          
      X   88      
      Y   89      
      Z   90      
      0   48      
      1   49      
      2   50       
      3   51       
      4   52       
      5   53       
      6   54       
      7   55       
      8   56       
      9   57

猜你喜欢

转载自blog.csdn.net/fnms88/article/details/82926051
今日推荐