简体   繁体   English

使用 selenium 在 chrome 中接受剪贴板权限请求

[英]Accept Clipboard permission request in chrome using selenium

I have want to copy some content and paste it and analyze it.我想复制一些内容并粘贴并分析它。

I have Headless Linux.我有无头 Linux。

When I copy it.当我复制它时。 I tried to paste it via pyperclip it gave me not implemented error.我试图通过pyperclip粘贴它,但它给了我not implemented的错误。 Then I tried and installed xclip.然后我尝试并安装了 xclip。

This Gave me error xsel: Can't open display: (null)这给了我错误xsel: Can't open display: (null)

So I tried another way.所以我尝试了另一种方法。 to use a javascript snippet to run it in python to get clipboard data.使用 javascript 片段在 python 中运行它以获取剪贴板数据。 that's the code那是代码

javascript_script = '''
    var done = arguments[0];
    setTimeout(async () => {
  const text = await navigator.clipboard.readText();
  console.log(text);
  done(text);
}, 3000);

     '''

driver.execute_async_script(javascript_script)

That's running good but require to accept allow clipboard.这运行良好,但需要接受允许剪贴板。 but i cannot find how to enable it.但我找不到如何启用它。

Need help to resolve with需要帮助解决

  • xclip or xclip 或
  • allow the clipboard access automatically自动允许剪贴板访问

Here is how to allow clipboard in Chrome + Selenium + Node.js :这是在Chrome + Selenium + Node.js中允许剪贴板的方法:

const {Builder} = require('selenium-webdriver');
const {Options} = require('selenium-webdriver/chrome');

const options = new Options()
options.setUserPreferences({
    profile: {
        content_settings: {
            exceptions: {
                clipboard: {
                    ['http://YOURURL,*']:
                        {
                            "expiration": "0",
                            "last_modified": Date.now(),
                            "model": 0,
                            "setting": 1
                        },
                }
            }
        }
    }
})

const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 selenium 在 Chrome 中接受对麦克风的请求 - Accept request to microphone in Chrome using selenium Selenium Python - 无头 Chrome 不复制到剪贴板 - Selenium Python - Headless Chrome not copying to clipboard Selenium 关闭/接受 Chrome 确认弹出窗口 - Selenium dismiss/accept Chrome confirmation popup window 在 Selenium Chrome 驱动程序中自动接受所有 cookies - Accept all cookies automatically in Selenium Chrome driver 如何在不使用 alert.accept() 的情况下使用 Selenium 在 Brave/Chrome 中禁用弹出窗口/警报? - How to disable popups/alerts in Brave/Chrome using Selenium without using alert.accept()? 使用 Selenium-webdriver 为 python 自动阻止 Chrome 请求? - Automate Chrome request blocking using Selenium-webdriver for python? 拒绝访问您无权使用 ChromeDriver 和 Chrome 通过 Selenium Python 访问此服务器上的“站点” - Access Denied You don't have permission to access "site" on this server using ChromeDriver and Chrome through Selenium Python 使用 Python fetch.fail_request 的 Selenium 4 chrome devtools 不会使请求失败,而是将其保持为待处理 - Selenium 4 chrome devtools using Python fetch.fail_request not failing the request but keeping it as pending 单击接受 cookies 按钮使用 Selenium - Clicking Accept cookies button using Selenium 如何使用硒在弹出窗口中接受警报? - How to accept alert in the popup window using selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM