代码拉取完成,页面将自动刷新
同步操作将从 Shmily/MicrosoftScore 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import json
import time
from playwright.sync_api import sync_playwright
from retrying import retry
from Exceptions.GainScorecardException import ScorecardException
def save_cookie_to_file(file_name, cookies):
with open(file_name, 'w') as file:
for cookie in cookies:
file.write(f"{json.dumps(cookie)}\n")
def read_cookie_from_file(file_name):
cookies = []
try:
for line in open(file_name, "r"):
cookies.append(json.loads(line))
except Exception as e:
return False
return True, cookies
def checkAriaAttr(page, selector, attribute):
# 使用evaluate方法获取DOM节点并判断是否具有aria-hidden属性
result = page.evaluate('(selector) => { \
const element = document.querySelector(selector); \
return element ? element.getAttribute("' + attribute + '") : null; \
}', selector)
return result
def timing(func):
"""
计算程序运行耗时
:param func: 函数,修饰器用法
:return: 内部函数
"""
def inner():
startTime = time.time()
print("开始时间:", startTime)
func()
endTime = time.time()
print("结束时间:", endTime)
timeDiff = endTime - startTime # 计算的时间差为程序的执行时间,单位为秒/s
print("时间间隔(单位/秒):", timeDiff)
return inner
# @timing
def main1():
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
context = browser.new_context()
page = context.new_page()
url = page.url
if "login.live.com" != url:
while True:
try:
page.goto("https://rewards.bing.com/", timeout=2000)
except Exception:
pass
url = page.url
if "login.live.com" in url:
page.wait_for_timeout(1000)
break
while True:
print("---------------#i0116-----------------")
info = page.wait_for_selector('#i0116', state='hidden', timeout=2000)
print(info.is_visible())
print(info.is_editable())
print(info.is_disabled())
print(info.is_enabled())
print("---------------#i0118-----------------")
info = page.wait_for_selector('#i0118', state='visible')
print(info.is_visible())
print(info.is_editable())
print(info.is_disabled())
print(info.is_enabled())
print()
print()
print()
page.wait_for_timeout(1000)
page.wait_for_timeout(1000000)
print("………………………………")
context.close()
browser.close()
def mainLogo():
import sys
from loguru import logger
logger.remove()
# 配置控制台输出
logger.add(sys.stdout, level='DEBUG')
# 配置日志输出
logger.add('./log/microsoftScore_{time: YYYY_MM_DD}.log', rotation='00:00', encoding="utf-8", level='INFO')
# 记录日志
logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")
@retry(stop_max_attempt_number=2, wait_fixed=3000)
def ok():
while True:
print("t")
raise ScorecardException("t")
if __name__ == "__main__":
try:
ok()
except ScorecardException:
pass
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。