From 35b9494d42888f99198212699aa64a37f109760d Mon Sep 17 00:00:00 2001 From: naibo Date: Mon, 10 Jul 2023 04:29:43 +0800 Subject: [PATCH] Change Database config name --- ElectronJS/server.js | 2 +- ExecuteStage/easyspider_executestage.py | 5 +++- ExecuteStage/requirements.txt | 1 + ExecuteStage/utils.py | 35 +++++++++++++------------ 4 files changed, 24 insertions(+), 19 deletions(-) diff --git a/ElectronJS/server.js b/ElectronJS/server.js index 1e0bd1e..d48014f 100644 --- a/ElectronJS/server.js +++ b/ElectronJS/server.js @@ -294,7 +294,7 @@ exports.start = function(port = 8074) { const config = { host: "localhost", port: 3306, - user: "your_username", + username: "your_username", password: "your_password", database: "your_database" }; diff --git a/ExecuteStage/easyspider_executestage.py b/ExecuteStage/easyspider_executestage.py index 54035fb..8a9d6a1 100644 --- a/ExecuteStage/easyspider_executestage.py +++ b/ExecuteStage/easyspider_executestage.py @@ -43,7 +43,7 @@ from PIL import Image # import uuid from threading import Thread, Event 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_creator, 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_creator, on_release_creator, write_to_csv, write_to_excel desired_capabilities = DesiredCapabilities.CHROME desired_capabilities["pageLoadStrategy"] = "none" @@ -1501,6 +1501,9 @@ if __name__ == '__main__': browser_t = MyChrome( options=options, chrome_options=option, executable_path=driver_path) elif cloudflare == 1: + if sys.platform == "linux": + import ssl + ssl._create_default_https_context = ssl._create_unverified_context # 忽略证书验证 browser_t = MyUCChrome( options=options, chrome_options=option, driver_executable_path=driver_path) print("Pass Cloudflare Mode") diff --git a/ExecuteStage/requirements.txt b/ExecuteStage/requirements.txt index 9e25e0c..cf8010e 100644 --- a/ExecuteStage/requirements.txt +++ b/ExecuteStage/requirements.txt @@ -8,3 +8,4 @@ openpyxl==3.1.2 pymysql==1.1.0 lxml==4.9.2 pynput==1.7.6 +undetected-chromedriver==3.4.7 \ No newline at end of file diff --git a/ExecuteStage/utils.py b/ExecuteStage/utils.py index 67f139e..0d70081 100644 --- a/ExecuteStage/utils.py +++ b/ExecuteStage/utils.py @@ -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 @@ -75,20 +75,20 @@ def on_release_creator(event, press_time): return on_release -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): @@ -223,12 +223,13 @@ class myMySQL: config = json.load(f) host = config["host"] port = config["port"] - user = config["user"] + user = config["username"] passwd = config["password"] db = config["database"] - except: + except Exception as e: print("读取配置文件失败,请检查配置文件:"+config_file+"是否存在。") print("Failed to read configuration file, please check if the configuration file: "+config_file+" exists.") + print(e) try: self.conn = pymysql.connect( host=host, port=port, user=user, passwd=passwd, db=db)