You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
70 lines
2.1 KiB
'''
|
|
获取 coin 现价, 并发邮件提醒
|
|
(先做单个coin)
|
|
'''
|
|
import datetime
|
|
import sys
|
|
import os
|
|
import time
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
|
|
|
|
from base.base_load_config import load_config, get_base_path
|
|
|
|
config_json = load_config()
|
|
base_project = get_base_path()
|
|
|
|
from playwright.sync_api import sync_playwright
|
|
import time
|
|
|
|
|
|
class CheckCoinCurrentPrice(object):
|
|
def __init__(self):
|
|
self.number_of_reminders = 5
|
|
self.reminder_interval = 60 * 5
|
|
self.target_price = 2.04
|
|
|
|
def main(self):
|
|
coins_link = {
|
|
'SUI': 'https://www.528btc.com/coin/33118.html'
|
|
}
|
|
url = coins_link['SUI']
|
|
with sync_playwright() as playwright:
|
|
browser = playwright.webkit.launch(headless=False)
|
|
context = browser.new_context(viewport={'width': 1920, 'height': 1080})
|
|
page = context.new_page()
|
|
|
|
# 使用选择器获取元素的文本内容
|
|
selector = '#detail_app_cid_5113 > div.money > div.sum > i > i.price_num.wordRise'
|
|
|
|
while True:
|
|
try:
|
|
page.goto(url)
|
|
page.wait_for_load_state('load')
|
|
time.sleep(3) # 确保页面完全加载
|
|
|
|
element = page.query_selector(selector)
|
|
if element:
|
|
price_text = element.inner_text()
|
|
print(f'SUI price: {price_text}' + '\t' + datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S'))
|
|
else:
|
|
print("Element not found")
|
|
context.close()
|
|
browser.close()
|
|
exit(0)
|
|
|
|
if float(price_text) > self.target_price:
|
|
break
|
|
except Exception as e:
|
|
print(e)
|
|
exit(0)
|
|
|
|
# 关闭浏览器
|
|
context.close()
|
|
browser.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
C = CheckCoinCurrentPrice()
|
|
C.main()
|
|
|