mirror of
https://github.com/NaiboWang/EasySpider.git
synced 2025-04-20 22:15:08 +08:00
Change keyboard module
This commit is contained in:
parent
261fb13006
commit
bb6e2b2881
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
2
ExecuteStage/.vscode/launch.json
vendored
2
ExecuteStage/.vscode/launch.json
vendored
@ -12,7 +12,7 @@
|
|||||||
"justMyCode": true,
|
"justMyCode": true,
|
||||||
// "args": ["--id", "[7]", "--read_type", "remote", "--headless", "0"]
|
// "args": ["--id", "[7]", "--read_type", "remote", "--headless", "0"]
|
||||||
// "args": ["--id", "[9]", "--read_type", "remote", "--headless", "0", "--saved_file_name", "YOUTUBE"]
|
// "args": ["--id", "[9]", "--read_type", "remote", "--headless", "0", "--saved_file_name", "YOUTUBE"]
|
||||||
"args": ["--id", "[6]", "--headless", "0", "--user_data", "1"]
|
"args": ["--id", "[3]", "--headless", "0", "--user_data", "1"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -39,10 +39,11 @@ import os
|
|||||||
from commandline_config import Config
|
from commandline_config import Config
|
||||||
import pytesseract
|
import pytesseract
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
from pynput.keyboard import Key, Listener
|
||||||
# import uuid
|
# import uuid
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
from myChrome import MyChrome, MyUCChrome
|
from myChrome import MyChrome, MyUCChrome
|
||||||
from utils import check_pause, download_image, get_output_code, isnull, lowercase_tags_in_xpath, myMySQL, new_line, on_press, on_release_creator, write_to_csv, write_to_excel
|
from utils import download_image, get_output_code, isnull, lowercase_tags_in_xpath, myMySQL, new_line, on_press, on_release_creator, write_to_csv, write_to_excel
|
||||||
desired_capabilities = DesiredCapabilities.CHROME
|
desired_capabilities = DesiredCapabilities.CHROME
|
||||||
desired_capabilities["pageLoadStrategy"] = "none"
|
desired_capabilities["pageLoadStrategy"] = "none"
|
||||||
|
|
||||||
@ -1504,19 +1505,20 @@ if __name__ == '__main__':
|
|||||||
threads.append(thread)
|
threads.append(thread)
|
||||||
thread.start()
|
thread.start()
|
||||||
# Set the pause operation
|
# Set the pause operation
|
||||||
if sys.platform != "linux":
|
# if sys.platform != "linux":
|
||||||
Thread(target=check_pause, args=("p", event)).start()
|
# Thread(target=check_pause, args=("p", event)).start()
|
||||||
else:
|
# else:
|
||||||
from pynput.keyboard import Key, Listener
|
time.sleep(3)
|
||||||
|
print("\n\n----------------------------------")
|
||||||
|
print("正在运行任务,按键盘p键可暂停任务的执行以便手工操作浏览器如输入验证码;如果想恢复任务的执行,请再次按p键。")
|
||||||
|
print("Running task, long press 'p' to pause the task for manual operation of the browser such as entering the verification code; If you want to resume the execution of the task, please long press 'p' again.")
|
||||||
|
print("----------------------------------\n\n")
|
||||||
# 使用监听器监听键盘输入
|
# 使用监听器监听键盘输入
|
||||||
with Listener(on_press=on_press, on_release=on_release_creator(event)) as listener:
|
with Listener(on_press=on_press, on_release=on_release_creator(event)) as listener:
|
||||||
listener.join()
|
listener.join()
|
||||||
|
|
||||||
time.sleep(5)
|
|
||||||
print("\n\n----------------------------------")
|
|
||||||
print("正在运行任务,长按键盘p键可暂停任务的执行以便手工操作浏览器如输入验证码;如果想恢复任务的执行,请再次长按p键。")
|
|
||||||
print("Running task, long press 'p' to pause the task for manual operation of the browser such as entering the verification code; If you want to resume the execution of the task, please long press 'p' again.")
|
|
||||||
print("----------------------------------\n\n")
|
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
thread.join()
|
thread.join()
|
||||||
|
@ -7,7 +7,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import uuid
|
import uuid
|
||||||
import keyboard
|
# import keyboard
|
||||||
from openpyxl import Workbook, load_workbook
|
from openpyxl import Workbook, load_workbook
|
||||||
import requests
|
import requests
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
@ -24,41 +24,41 @@ def is_valid_url(url):
|
|||||||
def lowercase_tags_in_xpath(xpath):
|
def lowercase_tags_in_xpath(xpath):
|
||||||
return re.sub(r"([A-Z]+)(?=[\[\]//]|$)", lambda x: x.group(0).lower(), xpath)
|
return re.sub(r"([A-Z]+)(?=[\[\]//]|$)", lambda x: x.group(0).lower(), xpath)
|
||||||
|
|
||||||
def on_press(key):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def on_release_creator(event):
|
def on_release_creator(event):
|
||||||
def on_release(key):
|
def on_release(key):
|
||||||
try:
|
try:
|
||||||
if key.char == 'p': # 当按下esc键时,退出监听
|
if key.char == 'p': # 当按下esc键时,退出监听
|
||||||
if event._flag == False:
|
if event._flag == False:
|
||||||
print("任务执行中,长按p键暂停执行。")
|
print("任务执行中,按p键暂停执行。")
|
||||||
print("Task is running, long press 'p' to pause.")
|
print("Task is running, long press 'p' to pause.")
|
||||||
# 设置Event的值为True,使得线程b可以继续执行
|
# 设置Event的值为True,使得线程b可以继续执行
|
||||||
event.set()
|
event.set()
|
||||||
else:
|
else:
|
||||||
# 设置Event的值为False,使得线程b暂停执行
|
# 设置Event的值为False,使得线程b暂停执行
|
||||||
print("任务已暂停,长按p键继续执行...")
|
print("任务已暂停,按p键继续执行...")
|
||||||
print("Task paused, press 'p' to continue...")
|
print("Task paused, press 'p' to continue...")
|
||||||
event.clear()
|
event.clear()
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return on_release
|
return on_release
|
||||||
|
|
||||||
def check_pause(key, event):
|
def on_press(key):
|
||||||
while True:
|
pass
|
||||||
if keyboard.is_pressed(key): # 按下p键,暂停程序
|
|
||||||
if event._flag == False:
|
# def check_pause(key, event):
|
||||||
print("任务执行中,长按p键暂停执行。")
|
# while True:
|
||||||
print("Task is running, long press 'p' to pause.")
|
# if keyboard.is_pressed(key): # 按下p键,暂停程序
|
||||||
# 设置Event的值为True,使得线程b可以继续执行
|
# if event._flag == False:
|
||||||
event.set()
|
# print("任务执行中,长按p键暂停执行。")
|
||||||
else:
|
# print("Task is running, long press 'p' to pause.")
|
||||||
# 设置Event的值为False,使得线程b暂停执行
|
# # 设置Event的值为True,使得线程b可以继续执行
|
||||||
print("任务已暂停,长按p键继续执行...")
|
# event.set()
|
||||||
print("Task paused, press 'p' to continue...")
|
# else:
|
||||||
event.clear()
|
# # 设置Event的值为False,使得线程b暂停执行
|
||||||
time.sleep(1) # 每秒检查一次
|
# print("任务已暂停,长按p键继续执行...")
|
||||||
|
# print("Task paused, press 'p' to continue...")
|
||||||
|
# event.clear()
|
||||||
|
# time.sleep(1) # 每秒检查一次
|
||||||
|
|
||||||
|
|
||||||
def download_image(url, save_directory):
|
def download_image(url, save_directory):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user