python抠图与pip install PIL报错

窗口命令pip install PIL(python3.6+selenium——2.53.1+pycharm)

from PIL import Image

from selenium import webdriver
d=webdriver.Firefox()
d.get('http://www.baidu.com')
# 窗口最大化
d.maximize_window()
time.sleep(1)
# 进行全屏截图
d.get_screenshot_as_file('c:mark666.png')
# 定位需要截图的元素位置
baidu=d.find_element('id','su')
# 获取element的顶点坐标
left=baidu.location['x']
top=baidu.location['y']
# 获取element的宽、高
elementwidth=baidu.location['x']+baidu.size['width']
elementheight=baidu.location['y']+baidu.size['height']
# 打开截图
p=Image.open('c:mark666.png')
# 使用Image的crop函数,从截图中再次截取我们需要的区域,进行图片剪切
p=p.crop((left,top,elementwidth,elementheight))
# 保存我们需要的的图片
p.save(r'c:mark6.png')



https://www.cnblogs.com/yuanzhoulvpi/p/9028713.html(导入pip install PIL报错参考) 可能是我进行了多次的安装和卸载,我在找着pip后输入pip install PIL报错:

could not find a version that satisfies the requirement PIL    no matching distribution found for PIL找着个说要下载pillow,下载进行安装报错,然后就在DOS找着pip的目录下输入pip install wheel ,把下载的Pillow‑5.1.1‑cp36‑cp36m‑win_amd64.whl
拖到C:UsersAdministratorAppDataLocalProgramsPythonPython36Scripts 安装python目录的scripts文件夹里,最后在DoS窗口
找着pip的目录下输入pip install PIL就成功了。 (多次进行安装卸载selenium可能出现这个问题)
 
原文地址:https://www.cnblogs.com/it-xian/p/10176125.html