相关疑难解决方法(0)

使用Selenium Python和chromedriver截取整页的屏幕截图

尝试了各种方法之后......我偶然发现这个页面采用了chromedriver,selenium和python的全页截图.

原始代码在这里:http://seleniumpythonqa.blogspot.com/2015/08/generate-full-page-screenshot-in-chrome.html(我在下面的帖子中复制代码)

它使用PIL,效果很棒!!!!! 然而,有一个问题......它捕获整个页面的固定标题和重复,并且在页面更改期间也错过了页面的某些部分.示例网址截取屏幕截图:

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

如何避免使用此代码重复标头...或者是否有更好的选项只使用python ... (我不知道java,不想使用java).

请参阅下面的当前结果和示例代码的屏幕截图.

带有重复标题的整页截图

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 = …
Run Code Online (Sandbox Code Playgroud)

python selenium webpage-screenshot selenium-chromedriver

27
推荐指数
13
解决办法
4万
查看次数

Selenium Chrome另存为pdf更改下载文件夹

我想将网站下载为 pdf 文件,它工作正常,但它应该将文件下载到特定路径,而不是将文件下载到我的默认下载目录。

import json
from selenium import webdriver

appState = {
    "recentDestinations": [
        {
            "id": "Save as PDF",
            "origin": "local"
        }
    ],
    "selectedDestinationId": "Save as PDF",
    "version": 2,
    'download.default_directory': 'C:\\Users\\Oli\\Google Drive',
    "download.directory_upgrade": True
}

profile = {'printing.print_preview_sticky_settings.appState': json.dumps(appState)}

chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option('prefs', profile)
chrome_options.add_argument('--kiosk-printing')

driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get('https://www.google.com/')
driver.execute_script('window.print();')
Run Code Online (Sandbox Code Playgroud)

顺便说一句,有人想用特定名称保护文件吗?

python selenium web-scraping

4
推荐指数
2
解决办法
7788
查看次数

将 Selenium ChromeDriver UserPreferences 设置为另存为 PDF

我正在使用 ChromeDriver 2.33 并使用 kiosk 打印自动单击“打印预览”对话框上的“打印”按钮,但是它将文档发送到打印机而不是 PDF。

我在这个堆栈溢出问题上尝试了解决方案,但无济于事。

这是我正在使用的代码:

ChromeOptions o = new ChromeOptions();
o.AddArgument("--kiosk-printing");
o.AddUserProfilePreference("printing.print_preview_sticky_settings.appState", "{\"version\":2,\"isGcpPromoDismissed\":false,\"selectedDestinationId\":\"Save as PDF\"");
chrome = new ChromeDriver(dir, o);
Run Code Online (Sandbox Code Playgroud)

谁能告诉我如何将打印机从实际打印机设置为 PDF?

selenium selenium-chromedriver selenium-webdriver

3
推荐指数
1
解决办法
7299
查看次数