From 68464c679ae5e1ae35e7e67e3b339ba0f939cbd3 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期三, 15 三月 2023 14:46:03 +0800 Subject: [PATCH] 选股宝板块优化 --- third_data/hot_block.py | 39 +++++++++++++++++++++++++++++++++++++-- 1 files changed, 37 insertions(+), 2 deletions(-) diff --git a/third_data/hot_block.py b/third_data/hot_block.py index 42e9588..ce398b9 100644 --- a/third_data/hot_block.py +++ b/third_data/hot_block.py @@ -1,7 +1,10 @@ """ 鐑棬鏉垮潡鐩戝惉 """ +import datetime +import json import logging +import socket import time from selenium import webdriver from selenium.webdriver.common.by import By @@ -18,7 +21,11 @@ print("----------------------") header = item.find_element(by=By.TAG_NAME, value="section").find_element(by=By.TAG_NAME, value="header") title = header.find_element(by=By.TAG_NAME, value="h3").text - total_rate = header.find_element(by=By.TAG_NAME, value="span").text + total_rate = None + try: + total_rate = header.find_element(by=By.TAG_NAME, value="span").text + except: + pass print(title, total_rate) contents = item.find_element(by=By.TAG_NAME, value="div").find_element(by=By.TAG_NAME, value="tbody").find_elements( @@ -44,15 +51,43 @@ def get_hot_block(callback): # 鍏堝惎鍔ㄦ祻瑙堝櫒 options = Options() + chrome_path = "res/chromedriver.exe" options.add_argument("--disable-blink-features") options.add_argument("--disable-blink-features=AutomationControlled") - driver = webdriver.Chrome(options=options) + driver = webdriver.Chrome(chrome_path, options=options) driver.get("https://xuangubao.cn/top-gainer") time.sleep(5) while True: time.sleep(3) + # 浜ゆ槗鏃堕棿鎵嶈瘑鍒� + time_str = datetime.datetime.now().strftime("%H%M%S") + if int(time_str) < int("092500") or int(time_str) > int("150000"): + continue + if int("113000") < int(time_str) < int("130000"): + continue try: result = __parseData(driver) callback(result) except Exception as e: logging.exception(e) + + +def upload_data(datas): + client = socket.socket() # 鐢熸垚socket锛岃繛鎺erver + ip_port = ("192.168.3.252", 9001) # server鍦板潃鍜岀鍙e彿锛堟渶濂芥槸10000浠ュ悗锛� + client.connect(ip_port) + data = {"type": 70, "data": datas} + client.send(json.dumps(data).encode("gbk")) + client.close() + + +# 鎵撳寘鍛戒护 +# cd D:\workspace\trade\third_data +# C:\Users\Administrator\AppData\Roaming\Python\Python37\Scripts\pyinstaller.exe hot_block.spec +if __name__ == "__main__": + def callback(result): + upload_data(result) + pass + + + get_hot_block(callback) -- Gitblit v1.8.0