发布时间:2019-08-02 11:14:11编辑:auto阅读(2008)
# -*- coding:utf-8 -*- from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait # 安装PIL包 # pip install pillow from PIL import Image driver = webdriver.Firefox() driver.get('https://www.zhihu.com/signup') # 找到验证码图片 ele = driver.find_element_by_xpath('//div[contains(@class,"Captcha")]/img') # 截取全屏 driver.save_screenshot('big.png') # 通过location定位x,y left = ele.location['x'] top = ele.location['y'] # 通过x,y的值拼接长和宽 right = left + ele.size['width'] bottom = top + ele.size['height'] # 创建img对象 # open()第一个参数 fp:filepath 文件路径 # 打开刚截取的全屏图 img = Image.open('big.png') # 定位到需要截取的地方 img = img.crop((left, top, right, bottom)) # 截取成功并保存到本地 img.save('captcha.png')
上一篇: 使用 python 创建最简单的 htt
下一篇: mac 10.12下安装Python3和
47568
45926
36869
34433
29042
25681
24530
19685
19205
17717
5542°
6119°
5653°
5707°
6663°
5448°
5453°
5960°
5934°
7260°