I have want to copy some content and paste it and analyze it.
I have Headless Linux.
When I copy it. I tried to paste it via pyperclip
it gave me not implemented
error. Then I tried and installed xclip.
This Gave me error 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. 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 :
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.