看板 Python 關於我們 聯絡資訊
from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from PIL import Image y_element = driver.find_element_by_id('你要定位點的id') # 先抓整個畫面 driver.save_screenshot('a.png') left = y_element.location['x'] top = y_element.location['y'] # 寬度 right = left + 60 bottom = top + y_element.size['height'] im = Image.open('a.png') # 再透過整個畫面截取需要部份 im = im.crop((left, top, right, bottom)) im.save(r"./captcha_img/captcha.png") # 使用selenium # 我是這樣做不知道有沒有更好的方法 ※ 引述《legov (lele)》之銘言: : 各位前輩好 : 我目前是用browser.set_windows_size(1200,4500) : browser.save_screenshot(‘abc.jpg’) : 截圖然後存檔,但是我想要截圖的網頁,他上方是廣告,我不想要整頁都截圖,想從網頁廣告的下方開始截圖,有方式可以這樣做嗎? : 謝謝 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.160.188.71 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1579021173.A.F95.html ※ 編輯: ctr1 (118.160.188.71 臺灣), 01/15/2020 01:01:18
legov: 已解決!感謝大大!謝謝 01/15 11:02
s860134: W3c有定義 element 的screenshot 吧 01/15 20:52
s860134: https://bit.ly/2tXBvMK 01/15 20:54