Long Press p

This commit is contained in:
naibo 2023-07-09 20:56:44 +08:00
parent 812faf52cc
commit fb99764222
13 changed files with 95 additions and 52 deletions

View File

@ -15,6 +15,8 @@ import time
import requests
from urllib.parse import urljoin
from lxml import etree
import undetected_chromedriver as uc
from pynput.keyboard import Key, Listener
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
@ -29,7 +31,6 @@ from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.support.ui import Select
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
import undetected_chromedriver as uc
import random
# import pandas as pd
from openpyxl import load_workbook, Workbook
@ -39,11 +40,10 @@ import os
from commandline_config import Config
import pytesseract
from PIL import Image
from pynput.keyboard import Key, Listener
# import uuid
from threading import Thread, Event
from myChrome import MyChrome, MyUCChrome
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
from utils import check_pause, download_image, get_output_code, isnull, lowercase_tags_in_xpath, myMySQL, new_line, on_press_creator, on_release_creator, write_to_csv, write_to_excel
desired_capabilities = DesiredCapabilities.CHROME
desired_capabilities["pageLoadStrategy"] = "none"
@ -1327,6 +1327,8 @@ class BrowserThread(Thread):
if __name__ == '__main__':
from multiprocessing import freeze_support
freeze_support() # 防止无限死循环多开
config = {
"id": [0],
"saved_file_name": "",
@ -1429,6 +1431,9 @@ if __name__ == '__main__':
option.add_argument(
f'--user-data-dir={absolute_user_data_folder}') # TMALL 反扒
option.add_argument("--profile-directory=Default")
options.add_argument(
f'--user-data-dir={absolute_user_data_folder}') # TMALL 反扒
options.add_argument("--profile-directory=Default")
if c.headless:
print("Headless mode")
@ -1445,7 +1450,7 @@ if __name__ == '__main__':
threads = []
for i in c.id:
print(options)
# print(options)
print("id: ", i)
if c.read_type == "remote":
print("remote")
@ -1506,21 +1511,32 @@ if __name__ == '__main__':
thread.start()
# Set the pause operation
# if sys.platform != "linux":
# 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")
# Thread(target=check_pause, args=("p", event)).start()
# else:
time.sleep(3)
press_time = {"duration": 0, "is_pressed": False}
print("\n\n----------------------------------")
print("正在运行任务按键盘p键可暂停任务的执行以便手工操作浏览器如输入验证码如果想恢复任务的执行请再次按p键。")
print("Running task, 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 press 'p' again.")
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:
try:
with Listener(on_press=on_press_creator(press_time, event), on_release=on_release_creator(event, press_time)) as listener:
listener.join()
except:
print("您的操作系统不支持暂停功能。")
print("Your operating system does not support the pause function.")
# print("线程长度:", len(threads) )
for thread in threads:
print()
thread.join()
for thread in threads:

View File

@ -7,7 +7,7 @@ import os
import re
import time
import uuid
# import keyboard
import keyboard
from openpyxl import Workbook, load_workbook
import requests
from urllib.parse import urlparse
@ -24,13 +24,20 @@ def is_valid_url(url):
def lowercase_tags_in_xpath(xpath):
return re.sub(r"([A-Z]+)(?=[\[\]//]|$)", lambda x: x.group(0).lower(), xpath)
def on_release_creator(event):
def on_release(key):
def on_press_creator(press_time, event):
def on_press(key):
try:
if key.char == 'p': # 当按下esc键时退出监听
if key.char == 'p':
if press_time["is_pressed"] == False: # 没按下p键时记录按下p键的时间
press_time["duration"] = time.time()
press_time["is_pressed"] = True
else: # 按下p键时判断按下p键的时间是否超过2.5秒
duration = time.time() - press_time["duration"]
if duration > 2.5:
if event._flag == False:
print("任务执行中按p键暂停执行。")
print("Task is running, long press 'p' to pause.")
print("Task is running, press 'p' to pause.")
# 设置Event的值为True使得线程b可以继续执行
event.set()
else:
@ -38,27 +45,50 @@ def on_release_creator(event):
print("任务已暂停按p键继续执行...")
print("Task paused, press 'p' to continue...")
event.clear()
press_time["duration"] = time.time()
press_time["is_pressed"] = False
# print("按下p键时间", press_time["duration"])
except:
pass
return on_press
def on_release_creator(event, press_time):
def on_release(key):
try:
# duration = time.time() - press_time["duration"]
# # print("松开p键时间", time.time(), "Duration: ", duration)
# if duration > 2.5 and key.char == 'p':
# if event._flag == False:
# print("任务执行中按p键暂停执行。")
# print("Task is running, press 'p' to pause.")
# # 设置Event的值为True使得线程b可以继续执行
# event.set()
# else:
# # 设置Event的值为False使得线程b暂停执行
# print("任务已暂停按p键继续执行...")
# print("Task paused, press 'p' to continue...")
# event.clear()
# press_time["duration"] = time.time()
press_time["is_pressed"] = False
except:
pass
return on_release
def on_press(key):
pass
# def check_pause(key, event):
# while True:
# if keyboard.is_pressed(key): # 按下p键暂停程序
# if event._flag == False:
# print("任务执行中长按p键暂停执行。")
# print("Task is running, long press 'p' to pause.")
# # 设置Event的值为True使得线程b可以继续执行
# event.set()
# else:
# # 设置Event的值为False使得线程b暂停执行
# print("任务已暂停长按p键继续执行...")
# print("Task paused, press 'p' to continue...")
# event.clear()
# time.sleep(1) # 每秒检查一次
def check_pause(key, event):
while True:
if keyboard.is_pressed(key): # 按下p键暂停程序
if event._flag == False:
print("任务执行中长按p键暂停执行。")
print("Task is running, long press 'p' to pause.")
# 设置Event的值为True使得线程b可以继续执行
event.set()
else:
# 设置Event的值为False使得线程b暂停执行
print("任务已暂停长按p键继续执行...")
print("Task paused, press 'p' to continue...")
event.clear()
time.sleep(1) # 每秒检查一次
def download_image(url, save_directory):

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,6 @@
cd ../Extension/manifest_v3/
node package.js
cd ../../ElectronJS
@echo off
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
@ -12,7 +15,6 @@ exit /B
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
rmdir /s /q C:\Users\q9823\AppData\Local\Temp\electron-packager
rmdir /s /q out
npm run package

View File

@ -34,16 +34,16 @@ def on_press_creator(press_time, event):
press_time["is_pressed"] = True
else: # 按下p键时判断按下p键的时间是否超过2.5秒
duration = time.time() - press_time["duration"]
if duration > 2.5:
if duration > 2:
if event._flag == False:
print("任务执行中,按p键暂停执行。")
print("Task is running, press 'p' to pause.")
print("任务执行中,按p键暂停执行。")
print("Task is running, long press 'p' to pause.")
# 设置Event的值为True使得线程b可以继续执行
event.set()
else:
# 设置Event的值为False使得线程b暂停执行
print("任务已暂停,按p键继续执行...")
print("Task paused, press 'p' to continue...")
print("任务已暂停,按p键继续执行...")
print("Task paused, long press 'p' to continue...")
event.clear()
press_time["duration"] = time.time()
press_time["is_pressed"] = False

View File

@ -22,7 +22,7 @@ A visual code-free/no-code web crawler/spider, just select the content you want
## 下载易采集/Download EasySpider
进入 [Releases Page](https://github.com/NaiboWang/EasySpider/releases) 下载最新版本。如果下载速度慢,可以考虑中国境内下载地址:[中国境内下载地址](https://github.com/NaiboWang/EasySpider/releases/download/v0.3.2/Download_Link_Address_in_China_Mainland.txt)。
进入 [Releases Page](https://github.com/NaiboWang/EasySpider/releases) 下载最新版本。如果下载速度慢,可以考虑中国境内下载地址:[中国境内下载地址](https://www.easyspider.cn/download.html)。
加QQ群从群文件下载是国内下载最快的方式但使用软件的过程中发生了问题求助还是请从GitHub提issue因为群主不怎么看群群号**682921940**。