如何将 Python Selenium 与 Electron JS App 连接起来
How to connect Python Selenium with Electron JS App
我正在构建一个简单的自动化应用程序,它将使用 Electron JS 获得良好的 GUI,然后使用 Python Selenium 来自动执行任务。
我刚刚开始尝试 运行 electron JS 应用程序,它显示没有名为 selenium 的模块。
这是我的 python (demo.py)
import time
import re
from selenium import webdriver
import webbrowser
import sys
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('https://example.com')
userid = browser.find_element_by_id('user')
time.sleep(1)
userpass = browser.find_element_by_id('password')
time.sleep(1)
userid.send_keys('aafasdf@gmail.com')
time.sleep(1)
userpass.send_keys('#jlasdjf#')
time.sleep(1)
userid.send_keys(Keys.RETURN)
userid.clear()
browser.refresh()
time.sleep(5)
print('Hello from Python!')
sys.stdout.flush()
And the goes my index.js file
-
function some(){
var ps = require("python-shell")
var path = require("path")
var options = {
scriptPath : path.join(__dirname,'../seleniumBro/'),
pythonPath : '/usr/local/bin/python3.8'
}
ps.PythonShell.run('../../seleniumBro/demo.py', options, function (err, results) {
if (err) throw err;
// swal(results[0]);
console.log(results[0])
});
}
当我 运行 应用程序时,我在控制台中收到此错误。
index.js:12 Uncaught Error: ModuleNotFoundError: No module named 'selenium'
at PythonShell.parseError (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:258:21)
at terminateIfNeeded (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:141:32)
at ChildProcess.<anonymous> (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:133:13)
at ChildProcess.emit (events.js:223:5)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
----- Python Traceback -----
File "/Users/rahul/Desktop/justDev/seleniumBro/demo.py", line 3, in <module>
from selenium import webdriver
我在 MAC OS。这也是新手。请帮忙。
按照我的看法。正如 pguardio 所说,您应该使用 Node.js,Selenium 也可用于节点。
我正在构建一个简单的自动化应用程序,它将使用 Electron JS 获得良好的 GUI,然后使用 Python Selenium 来自动执行任务。
我刚刚开始尝试 运行 electron JS 应用程序,它显示没有名为 selenium 的模块。
这是我的 python (demo.py)
import time
import re
from selenium import webdriver
import webbrowser
import sys
from selenium.webdriver.common.keys import Keys
browser = webdriver.Firefox()
browser.get('https://example.com')
userid = browser.find_element_by_id('user')
time.sleep(1)
userpass = browser.find_element_by_id('password')
time.sleep(1)
userid.send_keys('aafasdf@gmail.com')
time.sleep(1)
userpass.send_keys('#jlasdjf#')
time.sleep(1)
userid.send_keys(Keys.RETURN)
userid.clear()
browser.refresh()
time.sleep(5)
print('Hello from Python!')
sys.stdout.flush()
And the goes my index.js file
-
function some(){
var ps = require("python-shell")
var path = require("path")
var options = {
scriptPath : path.join(__dirname,'../seleniumBro/'),
pythonPath : '/usr/local/bin/python3.8'
}
ps.PythonShell.run('../../seleniumBro/demo.py', options, function (err, results) {
if (err) throw err;
// swal(results[0]);
console.log(results[0])
});
}
当我 运行 应用程序时,我在控制台中收到此错误。
index.js:12 Uncaught Error: ModuleNotFoundError: No module named 'selenium'
at PythonShell.parseError (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:258:21)
at terminateIfNeeded (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:141:32)
at ChildProcess.<anonymous> (/Users/rahul/Desktop/justDev/electronBro/hello-world/node_modules/python-shell/index.js:133:13)
at ChildProcess.emit (events.js:223:5)
at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
----- Python Traceback -----
File "/Users/rahul/Desktop/justDev/seleniumBro/demo.py", line 3, in <module>
from selenium import webdriver
我在 MAC OS。这也是新手。请帮忙。
按照我的看法。正如 pguardio 所说,您应该使用 Node.js,Selenium 也可用于节点。