参考:https://www.cnblogs.com/LanTianYou/p/5578621.html
# coding:utf8 from time import sleep from selenium import webdriver import json class Hiblog(object): def __init__(self, url1): self.url = url1 def screen_shot(self): driver = webdriver.PhantomJS() driver.get(self.url) driver.find_element_by_name("username").send_keys("admin") driver.find_element_by_name("password").send_keys("admin") driver.find_element_by_xpath("//button[@type='submit']").click() driver.viewportSize = {'width': 1024, 'height': 800} driver.maximize_window() sleep(5) driver.save_screenshot('test.png') print(driver.title) if __name__ == "__main__": url = "http://www.baidu.com" screen = Hiblog(url) screen.screen_shot()