diff --git a/fund.py b/funds/__init__.py similarity index 60% rename from fund.py rename to funds/__init__.py index 1db098a..cb72cce 100644 --- a/fund.py +++ b/funds/__init__.py @@ -1,13 +1,15 @@ + # import traceback +from abc import ABC, abstractmethod 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): +class Fund(ABC): + def __init__(self, url, mobile=True, headless=True): + self.url = url self.mobile_emulation = {'deviceName': 'iPad Mini'} self.mobile = mobile self.headless = headless @@ -21,7 +23,7 @@ class Fund(object): 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) + start_chrome(self.url, options=chrome_options) return self @@ -30,21 +32,10 @@ class Fund(object): print("value: ", value) kill_browser() - + @abstractmethod def login(self): - write('15359827092', into=S('input#tbname')) - write('c113w927j', into=S('input#tbpwd')) - click(S('input#protocolCheckbox')) - click(S('a#btn_login')) - + pass + + @abstractmethod 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 + pass \ No newline at end of file diff --git a/funds/efunds.py b/funds/efunds.py new file mode 100644 index 0000000..451682e --- /dev/null +++ b/funds/efunds.py @@ -0,0 +1,34 @@ +# import traceback +from email.mime.text import MIMEText +from smtplib import SMTP_SSL + +from helium import * + +from funds import Fund + + +class EFund(Fund): + """ + 易方达基金 + """ + def __init__(self, url="https://e.efunds.com.cn/", mobile=True, headless=True): + super().__init__(url, mobile=mobile, headless=headless) + + + def login(self): + write('15359827092', into=S('input#certID')) + write('DJUWwiN4ep9XzsN', into=S('input#tradepassword')) + click(S('div#agreementRadioBox')) + click(S('input#submitBtn')) + + def my_assets(self): + asset_el = S('td.f-tl.fis-col') + if not asset_el.exists: + wait_until(asset_el.exists) + print(f"{asset_el.web_element.text}") + print("资产总额:") + + +with EFund(headless=False, mobile=False) as fund: + fund.login() + fund.my_assets() \ No newline at end of file diff --git a/funds/gffunds.py b/funds/gffunds.py new file mode 100644 index 0000000..a4ea432 --- /dev/null +++ b/funds/gffunds.py @@ -0,0 +1,33 @@ +# import traceback +from email.mime.text import MIMEText +from smtplib import SMTP_SSL + +from helium import * + +from funds import Fund + + +class GfFund(Fund): + """ + 广发基金 + """ + def __init__(self, url="https://trade.gffunds.com.cn/login", mobile=True, headless=True): + super().__init__(url, mobile=mobile, headless=headless) + + def login(self): + write('15359827092', into=S('input#userName')) + write('Q6bcV7tvEw4jiZT', into=S('input#password')) + click(S('span.ant-checkbox')) + click(Text('登 录')) + + def my_assets(self): + asset_el = S('span.text-x3l') + if not asset_el.exists: + wait_until(asset_el.exists) + print("资产总额:") + print(f"{asset_el.web_element.text}") + + +with GfFund(headless=False, mobile=False) as fund: + fund.login() + fund.my_assets() \ No newline at end of file