| | |
| | | """ |
| | | 热门板块监听 |
| | | """ |
| | | import datetime |
| | | import json |
| | | import logging |
| | | import socket |
| | | import time |
| | | from selenium import webdriver |
| | | from selenium.webdriver.common.by import By |
| | |
| | | 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( |
| | |
| | | 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,连接server |
| | | ip_port = ("192.168.3.252", 9001) # server地址和端口号(最好是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) |