From 6153538672e50815c9d2819ed6ddc905c4e931bd Mon Sep 17 00:00:00 2001 From: chenwj <654891551@qq.com> Date: Mon, 21 Nov 2022 15:07:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=9B=B8=E5=85=B3=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto.py | 14 ++++--- auto_v2.py | 98 +++++++++++++++++++++++++++++++++++++++++++ auto_v3.py | 88 +++++++++++++++++++++++++++++++++++++++ chrome.py | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++ fund.py | 50 ++++++++++++++++++++++ get_data.py | 9 ++-- 6 files changed, 366 insertions(+), 10 deletions(-) create mode 100644 auto_v2.py create mode 100644 auto_v3.py create mode 100644 chrome.py create mode 100644 fund.py diff --git a/auto.py b/auto.py index dc56d7b..5abb92d 100644 --- a/auto.py +++ b/auto.py @@ -1,11 +1,15 @@ -from helium import * -from selenium.webdriver import ChromeOptions import time -chrome_options = ChromeOptions() -mobile_emulation = {'deviceName': 'iPhone XR'} -chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) +from helium import * +from selenium.webdriver import ChromeOptions +chrome_options = ChromeOptions() +chrome_options.add_argument('--no-sandbox') +# chrome_options.add_argument('--headless') +# mobile_emulation = {'deviceName': 'Apple iPhone XR'} +# chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) +# chrome_options.add_argument('user-agent="MQQBrowser/26 Mozilla/5.0 (Linux; U; Android 2.3.7; zh-cn; MB200 Build/GRJ22; CyanogenMod-7) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"') +chrome_options.add_argument('user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 16_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.29(0x18001d36) NetType/WIFI Language/zh_CN"') start_chrome("https://youdian.jindianle.com/", options=chrome_options) click(Text("您尚未登录,点击登录")) click(Text("密码登录")) diff --git a/auto_v2.py b/auto_v2.py new file mode 100644 index 0000000..e9be32f --- /dev/null +++ b/auto_v2.py @@ -0,0 +1,98 @@ +import time +import traceback + +from helium import * +from selenium.webdriver import ChromeOptions + +chrome_options = ChromeOptions() +mobile_emulation = {'deviceName': 'iPad Mini'} +chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) +#chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) +#chrome_options.add_experimental_option('useAutomationExtension', False) +chrome_options.add_argument('--no-sandbox') +# chrome_options.add_argument('--headless') +chrome_options.add_argument('user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"') +driver = start_chrome("https://youdian.jindianle.com/", options=chrome_options) +try: + click(Text("您尚未登录,点击登录")) + click(Text("密码登录")) + write("15359827092", into="请输入手机号") + write("c113w927j", into="请输入6-12位数字或字母") + click(Button("登 录")) + # 进入页面先点击关闭弹窗按钮 + _close = S('//*[@id="vue2_el"]/div/div[10]/div/p') + click(_close) + + #店内账本 + # click(Text("店内账本")) + # moneynum = S('//span[contains(@class, "gray3") and contains(@class, "moneynum")]') + # wait_until(moneynum.exists) + # if moneynum is not None: + # balance = moneynum.web_element.text + # print(f"金额还剩:{balance}") + # else: + # print("元素未找到") + # # 回退 + # back = S('#vue2_el > header > div.back > a') + # click(back) + + #选号记录 + # click(Text("选号记录")) + # # 回退 + # back = S('#vue2_el > header > div.back > a') + # click(back) + + + # 点击排列三 + pls = S('//*[@id="vue2_el"]/div/section/div[6]/div[4]/div[3]') + wait_until(pls.exists) + click(pls) + wait_until(Text('组选').exists) + click(Text('组选')) + # 普通投注-> 取消组3 + result = ['258', '357', '069', '168', '078', '267', '159', '339', '177', '366'] + for index, item in enumerate(result): + if len(set(item)) == 3: + click(Text('普通投注')) + for i in item: + ball_line = S(f'//*[@id="body"]/section/div[3]/div[2]/ul/li[{int(i) + 1}]/p[1]') + if ball_line.exists: + print(ball_line.web_element.text) + click(ball_line) + else: + print(f"{i}不存在") + wait_until(Text("组3").exists) + click(Text("组3")) + else: + click(Text('组3单式')) + if item[0] == item[1]: + double_ball = S(f'//*[@id="body"]/section/div[3]/div[1]/div[2]/ul/li[{int(item[0]) + 1}]/p') + single_ball = S(f'//*[@id="body"]/section/div[3]/div[2]/div[2]/ul/li[{int(item[2]) + 1}]/p') + else: + double_ball = S(f'//*[@id="body"]/section/div[3]/div[1]/div[2]/ul/li[{int(item[2]) + 1}]/p') + single_ball = S(f'//*[@id="body"]/section/div[3]/div[2]/div[2]/ul/li[{int(item[0]) + 1}]/p') + click(double_ball) + click(single_ball) + print(f"{index}: {item}") + wait_until(Text("下一步").exists) + click(Text("下一步")) + if index + 1 != len(result): + wait_until(Text("+继续添加").exists) + click(Text("+继续添加")) + wait_until(Text("保存").exists) + click(Text("保存")) + + # # 设置倍数后,再点击一次下一步 + # plus = Text("+") + # # click(plus) + # wait_until(Text("下一步").exists) + # click(Text("下一步")) + + # # 最后一步, 点击确认 + # wait_until(Text("确认").exists) + # click(Text("确认")) + print("完成。。。") + kill_browser() +except Exception as e: + print(traceback.format_exc()) + kill_browser() diff --git a/auto_v3.py b/auto_v3.py new file mode 100644 index 0000000..cb8de85 --- /dev/null +++ b/auto_v3.py @@ -0,0 +1,88 @@ +import time +import traceback + +from helium import * +from selenium.webdriver import ChromeOptions + +chrome_options = ChromeOptions() +mobile_emulation = {'deviceName': 'iPhone XR'} +chrome_options.add_experimental_option("mobileEmulation", mobile_emulation) +#chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) +#chrome_options.add_experimental_option('useAutomationExtension', False) +chrome_options.add_argument('--no-sandbox') +# chrome_options.add_argument('--headless') +chrome_options.add_argument('user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"') +driver = start_chrome("https://youdian.jindianle.com/", options=chrome_options) +try: + click(Text("您尚未登录,点击登录")) + click(Text("密码登录")) + write("15359827092", into="请输入手机号") + write("c113w927j", into="请输入6-12位数字或字母") + click(Button("登 录")) + # 进入页面先点击关闭弹窗按钮 + _close = S('//*[@id="vue2_el"]/div/div[10]/div/p') + click(_close) + + #店内账本 + # click(Text("店内账本")) + # moneynum = S('//span[contains(@class, "gray3") and contains(@class, "moneynum")]') + # wait_until(moneynum.exists) + # if moneynum is not None: + # balance = moneynum.web_element.text + # print(f"金额还剩:{balance}") + # else: + # print("元素未找到") + # # 回退 + # back = S('#vue2_el > header > div.back > a') + # click(back) + + #选号记录 + # click(Text("选号记录")) + # # 回退 + # back = S('#vue2_el > header > div.back > a') + # click(back) + + + # 点击排列三 + pls = S('//*[@id="vue2_el"]/div/section/div[6]/div[4]/div[3]') + wait_until(pls.exists) + click(pls) + wait_until(Text('组选').exists) + click(Text('组选')) + click(Text('普通投注')) + # 普通投注-> 取消组3 + # + result = ['168', '069', '348', '249', '078'] + for index, item in enumerate(result): + for i in item: + i = int(i) + 1 + ball_line = S(f'//*[@id="body"]/section/div[3]/div[2]/ul/li[{i}]/p[1]') + if ball_line.exists: + click(ball_line) + else: + print(f"{i-1}不存在") + print(f"{index}: {item}") + wait_until(Text("组3").exists) + click(Text("组3")) + wait_until(Text("下一步").exists) + click(Text("下一步")) + if index + 1 != len(result): + wait_until(Text("+继续添加").exists) + click(Text("+继续添加")) + wait_until(Text("保存").exists) + click(Text("保存")) + + # # 设置倍数后,再点击一次下一步 + # plus = Text("+") + # # click(plus) + # wait_until(Text("下一步").exists) + # click(Text("下一步")) + + # # 最后一步, 点击确认 + # wait_until(Text("确认").exists) + # click(Text("确认")) + print("完成。。。") + kill_browser() +except Exception as e: + print(traceback.format_exc()) + kill_browser() \ No newline at end of file diff --git a/chrome.py b/chrome.py new file mode 100644 index 0000000..d032abc --- /dev/null +++ b/chrome.py @@ -0,0 +1,117 @@ +# import traceback +from email.mime.text import MIMEText +from smtplib import SMTP_SSL + +from helium import * +from selenium.webdriver import ChromeOptions + + +class Chrome(object): + def __init__(self, mobile=True, headless=True): + self.mobile_emulation = {'deviceName': 'iPad Mini'} + self.mobile = mobile + self.headless = headless + + + def __enter__(self): + chrome_options = ChromeOptions() + chrome_options.add_argument('--no-sandbox') + if self.headless: + chrome_options.add_argument('--headless') + if self.mobile: + chrome_options.add_experimental_option("mobileEmulation", self.mobile_emulation) + chrome_options.add_argument('user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"') + start_chrome("https://youdian.jindianle.com/", options=chrome_options) + click(Text("您尚未登录,点击登录")) + click(Text("密码登录")) + write("15359827092", into="请输入手机号") + write("c113w927j", into="请输入6-12位数字或字母") + click(Button("登 录")) + # 进入页面先点击关闭弹窗按钮 + _close = S('//*[@id="vue2_el"]/div/div[10]/div/p') + click(_close) + return self + + def __exit__(self, type, value, trace): + kill_browser() + print("type: " + type + ", value = " + value) + + + def balance(self): + #店内账本 + click(Text("店内账本")) + moneynum = S('//span[contains(@class, "gray3") and contains(@class, "moneynum")]') + wait_until(moneynum.exists) + if moneynum is not None: + balance = moneynum.web_element.text + print(f"金额还剩:{balance}") + else: + print("元素未找到") + # 回退 + back = S('#vue2_el > header > div.back > a') + click(back) + + def pls(self, result=[]): + # 点击排列三 + _pls = S('//*[@id="vue2_el"]/div/section/div[6]/div[4]/div[3]') + wait_until(_pls.exists) + click(_pls) + zx = Text('组选') + if not zx.exists: + wait_until(zx.exists) + click(zx) + # 普通投注-> 取消组3 + # result = ['258', '357', '069', '168', '078', '267', '159', '339', '177', '366'] + for index, item in enumerate(result): + if len(set(item)) == 3: + click(Text('普通投注')) + for i in item: + ball_line = S(f'//*[@id="body"]/section/div[3]/div[2]/ul/li[{int(i) + 1}]/p[1]') + if ball_line.exists: + print(ball_line.web_element.text) + click(ball_line) + else: + print(f"{i}不存在") + group3 = Text("组3") + if not group3.exists: + wait_until(group3.exists) + click(group3) + else: + click(Text('组3单式')) + if item[0] == item[1]: + double_ball = S(f'//*[@id="body"]/section/div[3]/div[1]/div[2]/ul/li[{int(item[0]) + 1}]/p') + single_ball = S(f'//*[@id="body"]/section/div[3]/div[2]/div[2]/ul/li[{int(item[2]) + 1}]/p') + else: + double_ball = S(f'//*[@id="body"]/section/div[3]/div[1]/div[2]/ul/li[{int(item[2]) + 1}]/p') + single_ball = S(f'//*[@id="body"]/section/div[3]/div[2]/div[2]/ul/li[{int(item[0]) + 1}]/p') + click(double_ball) + click(single_ball) + print(f"{index}: {item}") + next_step = Text("下一步") + if not next_step.exists: + wait_until(next_step.exists) + click(next_step) + if index + 1 != len(result): + wait_until(Text("+继续添加").exists) + click(Text("+继续添加")) + #div.mult_numkeyboard > ul > li:nth-child(1) > p + #div.mult_numkeyboard > ul > li:nth-child(2) > p + #div.mult_numkeyboard > ul > li:nth-child(11) > p + save = Text("保存") + if not save.exists: + wait_until(save.exists) + click(save) + back_1 = S('a.backlink') + if not back_1.exists: + wait_until(back_1.exists) + click(back_1) + back_2 = S('div.back') + if not back_2.exists: + wait_until(back_2.exists) + click(back_2) + + + +with Chrome(headless=False) as chrome: + chrome.balance() + chrome.pls(result = ['258', '357', '069', '168', '078']) \ No newline at end of file diff --git a/fund.py b/fund.py new file mode 100644 index 0000000..1db098a --- /dev/null +++ b/fund.py @@ -0,0 +1,50 @@ +# import traceback +from email.mime.text import MIMEText +from smtplib import SMTP_SSL + +from helium import * +from selenium.webdriver import ChromeOptions + + +class Fund(object): + def __init__(self, mobile=True, headless=True): + self.mobile_emulation = {'deviceName': 'iPad Mini'} + self.mobile = mobile + self.headless = headless + + + def __enter__(self): + chrome_options = ChromeOptions() + chrome_options.add_argument('--no-sandbox') + if self.headless: + chrome_options.add_argument('--headless') + if self.mobile: + chrome_options.add_experimental_option("mobileEmulation", self.mobile_emulation) + chrome_options.add_argument('user-agent="Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"') + start_chrome("https://login.1234567.com.cn/login", options=chrome_options) + + return self + + def __exit__(self, type, value, trace): + print("type: ", type ) + print("value: ", value) + kill_browser() + + + def login(self): + write('15359827092', into=S('input#tbname')) + write('c113w927j', into=S('input#tbpwd')) + click(S('input#protocolCheckbox')) + click(S('a#btn_login')) + + def my_assets(self): + click(S('a.aui_close')) + elem_all_value = S('span#all_value') + wait_until(elem_all_value.exists) + print("资产总额:") + print(elem_all_value.web_element.text) + + +with Fund(headless=False, mobile=False) as fund: + fund.login() + fund.my_assets() \ No newline at end of file diff --git a/get_data.py b/get_data.py index 7857b9c..57cb4b1 100644 --- a/get_data.py +++ b/get_data.py @@ -1,11 +1,10 @@ -from requests_html import HTMLSession, HTML +from requests_html import HTML, HTMLSession +from retrying import retry from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -from retrying import retry from lottery import Lottery - session = HTMLSession() @retry(stop_max_attempt_number=3) @@ -18,9 +17,9 @@ def _get_data(url, lottery_type): draw_code = table_list.find("div.ball_box01")[0].text.replace('\n', '') last_id = lottery.insert(draw_issue, draw_date, draw_code) if last_id: - print(f"issue:{issue}数据写入完成。。。") + print(f"issue:{draw_issue}数据写入完成。。。") else: - print(f'issue:{issue}已经存在') + print(f'issue:{draw_issue}已经存在') def get_data(url, lottery_type): try: