[英]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需要帮助解决
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.