python实现自动网页截图并裁剪图片
2018-07-30 14:11
1016 查看
本文实例为大家分享了python自动网页截图并裁剪图片的具体代码,供大家参考,具体内容如下
代码:
# coding=utf-8 import time from selenium import webdriver from selenium.webdriver.chrome.options import Options from PIL import Image import os all_urls = ['http:/****edit'] def login(): chrome_options = Options() chrome_options.add_argument('--headless') driver = webdriver.Chrome(executable_path='./chromedriver',chrome_options=chrome_options) driver.set_window_size(1200, 741) driver.implicitly_wait(2) print('初始化中...') driver.get("http://x*****e") print('填写登录信息中...') acc = driver.find_element_by_id('login-email') pwd = driver.find_element_by_id('login-pass') btn = driver.find_element_by_tag_name('button') acc.send_keys('***') pwd.send_keys('***') btn.click() print('跳转到验证码页面中...') time.sleep(2) capta = driver.find_element_by_id('code') capta_input = input('请输入两步验证码:') capta.send_keys(capta_input) btn1 = driver.find_element_by_tag_name('button') btn1.click() time.sleep(2) print('跳转到创意编辑页面中...') return driver def get_screen(driver,urls): count = 1 for url in urls: driver.get(url) print('正在抓取--> %s'% url) count +=1 time.sleep(2) uid = url.split('/')[-2] cid = url.split('/')[-5] driver.get_screenshot_as_file("./screen_shot/{}-{}.png".format(uid,cid)) print("创意--> {}-{}.png 已经保存".format(uid,cid)) print('还剩 %s 个'% str(len(urls)-count)) def crop_img(): for img in os.listdir('./screen_shot'): if img.endswith('.png'): print('%s裁剪中。。'% img) im = Image.open('./screen_shot/%s'% img) x = 755 y = 162 w = 383 h = 346 region = im.crop((x, y, x+w, y+h)) region.save("./screenshot_final/%s" % img) if __name__ == '__main__': driver = login() get_screen(driver,all_urls) driver.quit() print('所有抓取结束') crop_img() print('所有裁剪结束')
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- Python 实现网页自动截图的示例讲解
- 基于JQuery实现的图片自动进行缩放和裁剪处理
- Python中使用 Selenium 实现网页截图实例
- 采用Python实现自动发送摄像头图片到微博
- 基于JQuery实现的图片自动进行缩放和裁剪处理
- JAVA实现自动打开URL对应的网页并保存为图片-不借助第三方API
- 使用Python模块webbrowser实现自动打开网页/刷新网页
- 利用python和httpwatch实现自动监控网页
- Tengine + Lua + GraphicsMagick 实现图片自动裁剪/缩放
- Tengine + Lua + GraphicsMagick 实现图片自动裁剪/缩放 - 腾勇的个人页面 - 开源中国社区
- [Python]croppic 裁剪图片的Python后台实现
- 网页中实现图片的自动放缩小
- [Python爬虫] Selenium自动访问Firefox和Chrome并实现搜索截图
- android 实现截图和图片裁剪
- 实现自动判断图片或flash,并在网页中显示
- Python中使用 Selenium 实现网页截图实例
- 实现自动判断图片或flash,并在网页中显示
- Tengine + Lua + GraphicsMagick 实现图片自动裁剪/缩放
- Python 下载网页 Jpg 图片以及 Gif 图片实现
- python简易爬虫来实现自动图片下载