久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<small id='aDSzM'></small><noframes id='aDSzM'>

    <i id='aDSzM'><tr id='aDSzM'><dt id='aDSzM'><q id='aDSzM'><span id='aDSzM'><b id='aDSzM'><form id='aDSzM'><ins id='aDSzM'></ins><ul id='aDSzM'></ul><sub id='aDSzM'></sub></form><legend id='aDSzM'></legend><bdo id='aDSzM'><pre id='aDSzM'><center id='aDSzM'></center></pre></bdo></b><th id='aDSzM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='aDSzM'><tfoot id='aDSzM'></tfoot><dl id='aDSzM'><fieldset id='aDSzM'></fieldset></dl></div>

      1. <legend id='aDSzM'><style id='aDSzM'><dir id='aDSzM'><q id='aDSzM'></q></dir></style></legend>

          <bdo id='aDSzM'></bdo><ul id='aDSzM'></ul>
        <tfoot id='aDSzM'></tfoot>
      2. 使用 Selenium Python 和 chromedriver 截取整頁截圖

        Take screenshot of full page with Selenium Python with chromedriver(使用 Selenium Python 和 chromedriver 截取整頁截圖)

          <i id='RI9nU'><tr id='RI9nU'><dt id='RI9nU'><q id='RI9nU'><span id='RI9nU'><b id='RI9nU'><form id='RI9nU'><ins id='RI9nU'></ins><ul id='RI9nU'></ul><sub id='RI9nU'></sub></form><legend id='RI9nU'></legend><bdo id='RI9nU'><pre id='RI9nU'><center id='RI9nU'></center></pre></bdo></b><th id='RI9nU'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RI9nU'><tfoot id='RI9nU'></tfoot><dl id='RI9nU'><fieldset id='RI9nU'></fieldset></dl></div>
            <bdo id='RI9nU'></bdo><ul id='RI9nU'></ul>

            • <tfoot id='RI9nU'></tfoot><legend id='RI9nU'><style id='RI9nU'><dir id='RI9nU'><q id='RI9nU'></q></dir></style></legend>
                <tbody id='RI9nU'></tbody>

                • <small id='RI9nU'></small><noframes id='RI9nU'>

                  本文介紹了使用 Selenium Python 和 chromedriver 截取整頁截圖的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  在嘗試了各種方法之后......我偶然發(fā)現了這個頁面,用 chromedriver、selenium 和 python 截取了整頁截圖.

                  原始代碼在

                  test.py

                  <代碼>"""此腳本使用此處的簡化版本:https://snipt.net/restrada/python-selenium-workaround-for-full-page-screenshot-using-chromedriver-2x/它包含 Jason Coutu 在評論中添加的*關鍵*更正."""導入系統從硒導入網絡驅動程序導入單元測試導入工具類測試(unittest.TestCase):"""演示:獲取Chrome生成全屏截圖"""默認設置(自我):self.driver = webdriver.Chrome()def 拆解(自我):self.driver.quit()def test_fullpage_screenshot(self):''' 生成文檔高度截圖 '''#url = "http://effbot.org/imagingbook/introduction.htm"url = "http://www.w3schools.com/js/default.asp"self.driver.get(url)util.fullpage_screenshot(self.driver,test.png")如果 __name__ == "__main__":unittest.main(argv=[sys.argv[0]])

                  util.py

                  導入操作系統進口時間從 PIL 導入圖像def fullpage_screenshot(驅動程序,文件):print("正在啟動 chrome 整頁截圖解決方法...")total_width = driver.execute_script("返回 document.body.offsetWidth")total_height = driver.execute_script("返回 document.body.parentNode.scrollHeight")viewport_width = driver.execute_script("return document.body.clientWidth")viewport_height = driver.execute_script("返回 window.innerHeight")print("總計: ({0}, {1}), 視口: ({2},{3})".format(total_width, total_height,viewport_width,viewport_height))矩形 = []我 = 0而我 <總高度:ii = 0top_height = i + viewport_height如果 top_height >總高度:頂部高度 = 總高度而 ii <總寬度:top_width = ii + viewport_width如果頂部寬度 >總寬度:頂部寬度 = 總寬度print("附加矩形 ({0},{1},{2},{3})".format(ii, i, top_width, top_height))rectangles.append((ii, i, top_width,top_height))ii = ii + viewport_widthi = i + viewport_height縫合圖像 = Image.new('RGB', (total_width, total_height))上一個 = 無部分 = 0對于矩形中的矩形:如果不是以前是無:driver.execute_script("window.scrollTo({0}, {1})".format(rectangle[0], rectangle[1]))print("滾動到 ({0},{1})".format(rectangle[0], rectangle[1]))time.sleep(0.2)file_name = "part_{0}.png".format(part)print("正在捕獲 {0} ...".format(file_name))driver.get_screenshot_as_file(file_name)截圖 = Image.open(file_name)如果矩形[1] + viewport_height >總高度:offset = (rectangle[0], total_height - viewport_height)別的:偏移量=(矩形[0],矩形[1])print("添加到帶有偏移量的拼接圖像 ({0}, {1})".format(offset[0],offset[1]))縫合圖像.粘貼(屏幕截圖,偏移)刪除截圖os.remove(文件名)部分 = 部分 + 1上一個 = 矩形縫合圖像.保存(文件)print("正在完成 chrome 整頁截圖的解決方法...")返回真

                  解決方案

                  工作原理:盡可能設置瀏覽器高度...

                  #coding=utf-8進口時間從硒導入網絡驅動程序從 selenium.webdriver.chrome.options 導入選項def test_fullpage_screenshot(self):chrome_options = 選項()chrome_options.add_argument('--headless')chrome_options.add_argument('--start-maximized')驅動程序 = webdriver.Chrome(chrome_options=chrome_options)driver.get("yoururlxxx")時間.sleep(2)#頁面上最長的元素ele=driver.find_element("xpath", '//div[@class="react-grid-layout layout"]')total_height = ele.size[身高"]+1000driver.set_window_size(1920, total_height) #訣竅時間.sleep(2)driver.save_screenshot("screenshot1.png")driver.quit()如果 __name__ == __main__":test_fullpage_screenshot()

                  After trying out various approaches... I have stumbled upon this page to take full-page screenshot with chromedriver, selenium and python.

                  The original code is here. (and I copy the code in this posting below)

                  It uses PIL and it works great! However, there is one issue... which is it captures fixed headers and repeats for the whole page and also misses some parts of the page during page change. sample url to take a screenshot:

                  http://www.w3schools.com/js/default.asp

                  How to avoid the repeated headers with this code... Or is there any better option which uses python only... ( i don't know java and do not want to use java).

                  Please see the screenshot of the current result and sample code below.

                  test.py

                  """
                  This script uses a simplified version of the one here:
                  https://snipt.net/restrada/python-selenium-workaround-for-full-page-screenshot-using-chromedriver-2x/
                  
                  It contains the *crucial* correction added in the comments by Jason Coutu.
                  """
                  
                  import sys
                  
                  from selenium import webdriver
                  import unittest
                  
                  import util
                  
                  class Test(unittest.TestCase):
                      """ Demonstration: Get Chrome to generate fullscreen screenshot """
                  
                      def setUp(self):
                          self.driver = webdriver.Chrome()
                  
                      def tearDown(self):
                          self.driver.quit()
                  
                      def test_fullpage_screenshot(self):
                          ''' Generate document-height screenshot '''
                          #url = "http://effbot.org/imagingbook/introduction.htm"
                          url = "http://www.w3schools.com/js/default.asp"
                          self.driver.get(url)
                          util.fullpage_screenshot(self.driver, "test.png")
                  
                  
                  if __name__ == "__main__":
                      unittest.main(argv=[sys.argv[0]])
                  

                  util.py

                  import os
                  import time
                  
                  from PIL import Image
                  
                  def fullpage_screenshot(driver, file):
                  
                          print("Starting chrome full page screenshot workaround ...")
                  
                          total_width = driver.execute_script("return document.body.offsetWidth")
                          total_height = driver.execute_script("return document.body.parentNode.scrollHeight")
                          viewport_width = driver.execute_script("return document.body.clientWidth")
                          viewport_height = driver.execute_script("return window.innerHeight")
                          print("Total: ({0}, {1}), Viewport: ({2},{3})".format(total_width, total_height,viewport_width,viewport_height))
                          rectangles = []
                  
                          i = 0
                          while i < total_height:
                              ii = 0
                              top_height = i + viewport_height
                  
                              if top_height > total_height:
                                  top_height = total_height
                  
                              while ii < total_width:
                                  top_width = ii + viewport_width
                  
                                  if top_width > total_width:
                                      top_width = total_width
                  
                                  print("Appending rectangle ({0},{1},{2},{3})".format(ii, i, top_width, top_height))
                                  rectangles.append((ii, i, top_width,top_height))
                  
                                  ii = ii + viewport_width
                  
                              i = i + viewport_height
                  
                          stitched_image = Image.new('RGB', (total_width, total_height))
                          previous = None
                          part = 0
                  
                          for rectangle in rectangles:
                              if not previous is None:
                                  driver.execute_script("window.scrollTo({0}, {1})".format(rectangle[0], rectangle[1]))
                                  print("Scrolled To ({0},{1})".format(rectangle[0], rectangle[1]))
                                  time.sleep(0.2)
                  
                              file_name = "part_{0}.png".format(part)
                              print("Capturing {0} ...".format(file_name))
                  
                              driver.get_screenshot_as_file(file_name)
                              screenshot = Image.open(file_name)
                  
                              if rectangle[1] + viewport_height > total_height:
                                  offset = (rectangle[0], total_height - viewport_height)
                              else:
                                  offset = (rectangle[0], rectangle[1])
                  
                              print("Adding to stitched image with offset ({0}, {1})".format(offset[0],offset[1]))
                              stitched_image.paste(screenshot, offset)
                  
                              del screenshot
                              os.remove(file_name)
                              part = part + 1
                              previous = rectangle
                  
                          stitched_image.save(file)
                          print("Finishing chrome full page screenshot workaround...")
                          return True
                  

                  解決方案

                  How it works: set browser height as longest as you can...

                  #coding=utf-8
                  import time
                  from selenium import webdriver
                  from selenium.webdriver.chrome.options import Options
                  
                  def test_fullpage_screenshot(self):
                      chrome_options = Options()
                      chrome_options.add_argument('--headless')
                      chrome_options.add_argument('--start-maximized')
                      driver = webdriver.Chrome(chrome_options=chrome_options)
                      driver.get("yoururlxxx")
                      time.sleep(2)
                      
                      #the element with longest height on page
                      ele=driver.find_element("xpath", '//div[@class="react-grid-layout layout"]')
                      total_height = ele.size["height"]+1000
                      
                      driver.set_window_size(1920, total_height)      #the trick
                      time.sleep(2)
                      driver.save_screenshot("screenshot1.png")
                      driver.quit()
                  
                  if __name__ == "__main__":
                      test_fullpage_screenshot()
                  

                  這篇關于使用 Selenium Python 和 chromedriver 截取整頁截圖的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                  <legend id='xq6FM'><style id='xq6FM'><dir id='xq6FM'><q id='xq6FM'></q></dir></style></legend>
                  1. <tfoot id='xq6FM'></tfoot>
                      • <i id='xq6FM'><tr id='xq6FM'><dt id='xq6FM'><q id='xq6FM'><span id='xq6FM'><b id='xq6FM'><form id='xq6FM'><ins id='xq6FM'></ins><ul id='xq6FM'></ul><sub id='xq6FM'></sub></form><legend id='xq6FM'></legend><bdo id='xq6FM'><pre id='xq6FM'><center id='xq6FM'></center></pre></bdo></b><th id='xq6FM'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xq6FM'><tfoot id='xq6FM'></tfoot><dl id='xq6FM'><fieldset id='xq6FM'></fieldset></dl></div>
                        • <bdo id='xq6FM'></bdo><ul id='xq6FM'></ul>

                          <small id='xq6FM'></small><noframes id='xq6FM'>

                            <tbody id='xq6FM'></tbody>

                            主站蜘蛛池模板: 日韩福利视频 | 久久精品亚洲精品 | 四季久久免费一区二区三区四区 | 国产一区二区三区在线 | 久热免费在线 | 国产成人精品久久久 | 91 久久| 免费一区| 国产一区二区三区四 | 亚洲视频a| 欧美日韩久久 | 久久狠狠 | 神马福利 | 日韩精品1区2区3区 爱爱综合网 | 成人免费影院 | 日韩欧美中文字幕在线观看 | 国产精品久久久久久久久免费桃花 | 草草网 | 人人操日日干 | 紧缚调教一区二区三区视频 | 精品国产欧美一区二区 | 在线成人免费观看 | 狠狠色网 | 国产精品无码久久久久 | 国产日韩欧美在线 | 在线观看a视频 | 视频一二三区 | 欧美黄色一区 | 国产精品视频999 | 亚洲精品乱码久久久久久9色 | 成人免费视频网站在线看 | 中文字幕日韩欧美 | 精品视频免费 | 日韩成人在线电影 | 日韩电影一区二区三区 | 一区二区三区在线免费看 | 亚洲精品中文在线观看 | 欧美 日韩 国产 成人 | 国产一区二区欧美 | 成人av免费| 无码日韩精品一区二区免费 |