作者wsybu (%小步步%)
看板Python
标题Re: [问题] Selenium save_screenshot 解析度问题
时间Thu Jul 16 16:20:25 2020
※ 引述《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://webptt.com/cn.aspx?n=bbs/Python/M.1594887627.A.2D3.html
※ 编辑: wsybu (60.250.32.15 台湾), 07/16/2020 16:20:51