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:\Users\Administrator\AppData\Local\Programs\Python\Python36\Scripts 安裝python目錄的scripts文件夾里,最后在DoS窗口
找着pip的目錄下輸入pip install PIL就成功了。 (多次進行安裝卸載selenium可能出現這個問題)
 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM