Python to implement screen capture code and function of the detailed _python

Source: Internet
Author: User

Nonsense not to say, first to see the Python implementation screen capture code, the specific code as follows:

From selenium import webdriver
import time
def capture (URL, save_fn= "Capture.png"):
browser = webdriver. Firefox () # get local session of Firefox
Browser.set_window_size (1200, 900)
browser.get (URL) # Load page
Browser.execute_script ("" "
(function () {
var y = 0;
var step =;
Window.Scroll (0, 0);
function f () {
if (Y < document.body.scrollHeight) {
y = = step;
Window.Scroll (0, y);
SetTimeout (f, m);
} else {
window.scroll (0, 0);
Document.title + = "Scroll-done";
}
SetTimeout (f, 1000);
}) ();
""")
For I in Xrange (m):
if "Scroll-done" in Browser.title:
break
time.sleep (1)
browser.save_ Screenshot (SAVE_FN)
browser.close ()
if __name__ = = "__main__":
Capture (Http://www.jb51.net)

The function of Pythony to implement screen screenshots is described as follows:

#-*-coding:cp936-*-import time,image import OS, Win32gui, Win32ui, Win32con, Win32API def window_capture (Dpath): ' "' screenshot function, call method Window_capture (' d:\\ '), return picture filename for specified saved directory, filename format: date. jpg: 2009328224853.jpg ' hwnd = 0 HWNDDC = Win32 Gui. GETWINDOWDC (HWND) Mfcdc=win32ui. Createdcfromhandle (HWNDDC) Savedc=mfcdc.createcompatibledc () Savebitmap = Win32ui. CreateBitmap () Moniterdev=win32api. Enumdisplaymonitors (none,none) w = moniterdev[0][2][2] h = moniterdev[0][2][3] #print w,h #图片大小 savebitmap.createcom Patiblebitmap (MFCDC, W, h) savedc.selectobject (Savebitmap) Savedc.bitblt ((0,0), (W, h), MFCDC, (0,0), Win32con.
srccopy) Cc=time.gmtime () bmpname=str (cc[0]) +str (cc[1)) +str (cc[2]) +str (cc[3]+8) +str (cc[4)) +str (cc[5)) + '. bmp ' 
Savebitmap.savebitmapfile (SaveDC, Bmpname) Image.open (bmpname). Save (bmpname[:-4]+ ". jpg") os.remove (Bmpname) jpgname=bmpname[:-4]+ '. jpg ' djpgname=dpath+jpgname Copy_command = ' Move%s%s '% (Jpgname, djpgname) Os.popen (copy_comma nd) return bmpname[: -4]+ '. jpg ' #调用截屏函数 window_capture (' d:\\ ') 

The above is a small set to share the Python screen capture of the code and function of the detailed explanation, I hope to help you, if you have any questions welcome to my message, small series will promptly reply to everyone, in this there is a lot of thanks to the cloud Habitat Community support site!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.