首页 > 解决方案 > 如何在 python 中请求输入时在后台运行 selenium 脚本

问题描述

我正在使用 python 自动化一些任务,我使用 selenium 来完成它。但我希望它在后台运行时询问用户输入(我不是指无头模式)。我希望终端看起来像 Metasploit 控制台中的那种,我们可以在后台运行漏洞利用或作业时做其他事情。

假设我example.com在 python3 中抓取网页

from selenuim import webdriver
driver=webdriver.Firefox(executable_path='blaah')
driver.get('https://example.com')
while True:
 #do something
 # do something else.
 # A loop starts here for any other task
  for i in range(something):
     #do somethings else

当它执行这些循环时,我想要求用户输入。但这不应该影响循环。exit但是如果用户说没有关闭硒窗口,我确实希望循环中断。例如:

if userInp.lower()=='exit':
 print("EXIting now")
 # DO SOMETHING that will affect the selenium window.
 #Like logging out of an account if its logged in

标签: pythonpython-3.xmultithreadingseleniumselenium-webdriver

解决方案


推荐阅读