mirror of
https://github.com/NaiboWang/EasySpider.git
synced 2025-04-22 23:24:22 +08:00
Long Press p
This commit is contained in:
parent
812faf52cc
commit
fb99764222
@ -15,6 +15,8 @@ import time
|
|||||||
import requests
|
import requests
|
||||||
from urllib.parse import urljoin
|
from urllib.parse import urljoin
|
||||||
from lxml import etree
|
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.chrome.options import Options
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.webdriver.common.action_chains import ActionChains
|
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.support.ui import Select
|
||||||
from selenium.webdriver import ActionChains
|
from selenium.webdriver import ActionChains
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
import undetected_chromedriver as uc
|
|
||||||
import random
|
import random
|
||||||
# import pandas as pd
|
# import pandas as pd
|
||||||
from openpyxl import load_workbook, Workbook
|
from openpyxl import load_workbook, Workbook
|
||||||
@ -39,11 +40,10 @@ 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 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 = DesiredCapabilities.CHROME
|
||||||
desired_capabilities["pageLoadStrategy"] = "none"
|
desired_capabilities["pageLoadStrategy"] = "none"
|
||||||
|
|
||||||
@ -1327,6 +1327,8 @@ class BrowserThread(Thread):
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
from multiprocessing import freeze_support
|
||||||
|
freeze_support() # 防止无限死循环多开
|
||||||
config = {
|
config = {
|
||||||
"id": [0],
|
"id": [0],
|
||||||
"saved_file_name": "",
|
"saved_file_name": "",
|
||||||
@ -1429,6 +1431,9 @@ if __name__ == '__main__':
|
|||||||
option.add_argument(
|
option.add_argument(
|
||||||
f'--user-data-dir={absolute_user_data_folder}') # TMALL 反扒
|
f'--user-data-dir={absolute_user_data_folder}') # TMALL 反扒
|
||||||
option.add_argument("--profile-directory=Default")
|
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:
|
if c.headless:
|
||||||
print("Headless mode")
|
print("Headless mode")
|
||||||
@ -1445,7 +1450,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
threads = []
|
threads = []
|
||||||
for i in c.id:
|
for i in c.id:
|
||||||
print(options)
|
# print(options)
|
||||||
print("id: ", i)
|
print("id: ", i)
|
||||||
if c.read_type == "remote":
|
if c.read_type == "remote":
|
||||||
print("remote")
|
print("remote")
|
||||||
@ -1506,21 +1511,32 @@ if __name__ == '__main__':
|
|||||||
thread.start()
|
thread.start()
|
||||||
# Set the pause operation
|
# Set the pause operation
|
||||||
# if sys.platform != "linux":
|
# 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()
|
# Thread(target=check_pause, args=("p", event)).start()
|
||||||
# else:
|
# else:
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
press_time = {"duration": 0, "is_pressed": False}
|
||||||
print("\n\n----------------------------------")
|
print("\n\n----------------------------------")
|
||||||
print("正在运行任务,按键盘p键可暂停任务的执行以便手工操作浏览器如输入验证码;如果想恢复任务的执行,请再次按p键。")
|
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("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")
|
print("----------------------------------\n\n")
|
||||||
# 使用监听器监听键盘输入
|
# 使用监听器监听键盘输入
|
||||||
with Listener(on_press=on_press, on_release=on_release_creator(event)) as listener:
|
try:
|
||||||
listener.join()
|
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:
|
for thread in threads:
|
||||||
|
print()
|
||||||
thread.join()
|
thread.join()
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
|
@ -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
|
||||||
@ -23,42 +23,72 @@ 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_release_creator(event):
|
|
||||||
|
def on_press_creator(press_time, event):
|
||||||
|
def on_press(key):
|
||||||
|
try:
|
||||||
|
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, 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
|
||||||
|
# print("按下p键时间:", press_time["duration"])
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
return on_press
|
||||||
|
|
||||||
|
def on_release_creator(event, press_time):
|
||||||
def on_release(key):
|
def on_release(key):
|
||||||
try:
|
try:
|
||||||
if key.char == 'p': # 当按下esc键时,退出监听
|
# duration = time.time() - press_time["duration"]
|
||||||
if event._flag == False:
|
# # print("松开p键时间:", time.time(), "Duration: ", duration)
|
||||||
print("任务执行中,按p键暂停执行。")
|
# if duration > 2.5 and key.char == 'p':
|
||||||
print("Task is running, long press 'p' to pause.")
|
# if event._flag == False:
|
||||||
# 设置Event的值为True,使得线程b可以继续执行
|
# print("任务执行中,按p键暂停执行。")
|
||||||
event.set()
|
# print("Task is running, press 'p' to pause.")
|
||||||
else:
|
# # 设置Event的值为True,使得线程b可以继续执行
|
||||||
# 设置Event的值为False,使得线程b暂停执行
|
# event.set()
|
||||||
print("任务已暂停,按p键继续执行...")
|
# else:
|
||||||
print("Task paused, press 'p' to continue...")
|
# # 设置Event的值为False,使得线程b暂停执行
|
||||||
event.clear()
|
# print("任务已暂停,按p键继续执行...")
|
||||||
|
# print("Task paused, press 'p' to continue...")
|
||||||
|
# event.clear()
|
||||||
|
# press_time["duration"] = time.time()
|
||||||
|
press_time["is_pressed"] = False
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return on_release
|
return on_release
|
||||||
|
|
||||||
def on_press(key):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# def check_pause(key, event):
|
def check_pause(key, event):
|
||||||
# while True:
|
while True:
|
||||||
# if keyboard.is_pressed(key): # 按下p键,暂停程序
|
if keyboard.is_pressed(key): # 按下p键,暂停程序
|
||||||
# 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()
|
||||||
# time.sleep(1) # 每秒检查一次
|
time.sleep(1) # 每秒检查一次
|
||||||
|
|
||||||
|
|
||||||
def download_image(url, save_directory):
|
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.
@ -1,3 +1,6 @@
|
|||||||
|
cd ../Extension/manifest_v3/
|
||||||
|
node package.js
|
||||||
|
cd ../../ElectronJS
|
||||||
@echo off
|
@echo off
|
||||||
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
|
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
|
||||||
if '%errorlevel%' NEQ '0' (
|
if '%errorlevel%' NEQ '0' (
|
||||||
@ -12,7 +15,6 @@ exit /B
|
|||||||
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
|
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
|
||||||
pushd "%CD%"
|
pushd "%CD%"
|
||||||
CD /D "%~dp0"
|
CD /D "%~dp0"
|
||||||
|
|
||||||
rmdir /s /q C:\Users\q9823\AppData\Local\Temp\electron-packager
|
rmdir /s /q C:\Users\q9823\AppData\Local\Temp\electron-packager
|
||||||
rmdir /s /q out
|
rmdir /s /q out
|
||||||
npm run package
|
npm run package
|
||||||
|
@ -34,16 +34,16 @@ def on_press_creator(press_time, event):
|
|||||||
press_time["is_pressed"] = True
|
press_time["is_pressed"] = True
|
||||||
else: # 按下p键时,判断按下p键的时间是否超过2.5秒
|
else: # 按下p键时,判断按下p键的时间是否超过2.5秒
|
||||||
duration = time.time() - press_time["duration"]
|
duration = time.time() - press_time["duration"]
|
||||||
if duration > 2.5:
|
if duration > 2:
|
||||||
if event._flag == False:
|
if event._flag == False:
|
||||||
print("任务执行中,按p键暂停执行。")
|
print("任务执行中,长按p键暂停执行。")
|
||||||
print("Task is running, 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, long press 'p' to continue...")
|
||||||
event.clear()
|
event.clear()
|
||||||
press_time["duration"] = time.time()
|
press_time["duration"] = time.time()
|
||||||
press_time["is_pressed"] = False
|
press_time["is_pressed"] = False
|
||||||
|
@ -22,7 +22,7 @@ A visual code-free/no-code web crawler/spider, just select the content you want
|
|||||||
|
|
||||||
## 下载易采集/Download EasySpider
|
## 下载易采集/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**。
|
加QQ群从群文件下载是国内下载最快的方式,但使用软件的过程中发生了问题求助还是请从GitHub提issue,因为群主不怎么看群,群号:**682921940**。
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user