提问人:ahmed osama 提问时间:11/15/2023 最后编辑:ahmed osama 更新时间:11/16/2023 访问量:57
如何解决Python中的Try和Except Error?
How to solve Try and Except Error in Python?
问:
我编写了一个函数来重新启动 VPN,以便在发生验证码错误时更改我的 IP,但该函数用于任何错误,而不仅仅是验证码错误。
获取 Virustotal Captcha 的 HTML
captcha = wait.until(EC.element_to_be_clickable((driver.execute_script("return document.querySelector('vt-ui-shell').shadowRoot.querySelector('captchaContainer')"))))
Virustotal 验证码 HTML
def restart_program(program_path, current_position, driver):
# Save the current position to a file
with open('restart_position.txt', 'w') as f:
f.write(str(current_position))
# Wait for 1 minute
print("Waiting for 1 minute...")
time.sleep(60)
# Restart the program
try:
print(f"Restarting {program_path}")
subprocess.run(["taskkill", "/f", "/im", os.path.basename(program_path)], check=True)
subprocess.Popen([program_path], shell=True)
except subprocess.CalledProcessError as e:
print(f"Error: {e}")
# Quit the browser
driver.quit()
主要
if __name__ == "__main__":
program_path = r"C:\Program Files\Cloudflare\Cloudflare WARP\Cloudflare WARP.exe"
while True:
try:
driver = webdriver.Chrome()
# Read the restart position from the file
try:
with open('restart_position.txt', 'r') as f:
restart_position = int(f.read())
except FileNotFoundError:
restart_position = 0
with open('IOCs.txt', 'r') as file:
IOCs = [line.strip() for line in file]
for i, IOC in enumerate(IOCs[restart_position:], start=restart_position):
perform_Scan(IOC)
答: 暂无答案
评论