看板 Python 關於我們 聯絡資訊
※ 引述《kiey (煉)》之銘言: : 小弟要擷取網頁上的某個區塊 : 使用 : mobileEmulation = {"deviceName": "iPhone 6 Plus"} : options = webdriver.ChromeOptions() : options.add_experimental_option('mobileEmulation', mobileEmulation) : options.add_argument('--log-level=3') : options.add_argument('–no-sandbox') : driver = webdriver.Chrome(chrome_options=options, : executable_path='C:\\chromedriver.exe') : driver.get(url) : driver.save_screenshot(path) : 但是在抓的時候他會閃一下 : 抓出來的圖就跟原來的解析度不太一樣 : 導致我後來要用 : im = im.crop((left, top, right, bottom)) : 的時候 : 無法抓到正確的位置 : 不知道有沒有先進有遇過類似問題 : 是怎麼解決的呢? 之前要使用selenium抓全畫面時候有google到一個寫法 height = driver.execute_script("return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);") driver.set_window_size(1200, height + 50) 這樣抓下來的圖片就會是1200寬 + 全頁面 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.250.32.15 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1594887627.A.2D3.html ※ 編輯: wsybu (60.250.32.15 臺灣), 07/16/2020 16:20:51