monadscore_query.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import os
  2. from playwright.sync_api import sync_playwright
  3. import time
  4. def get_wallet_detail(wallet_address: str, page):
  5. # 定义输入框和按钮的选择器
  6. input_selector = '#root > div > div > div.min-h-screen.overflow-hidden.sm\\:ml-0 > div:nth-child(3) > div > div > div.flex.flex-col.space-y-4 > input'
  7. button_selector = '#root > div > div > div.min-h-screen.overflow-hidden.sm\\:ml-0 > div:nth-child(3) > div > div > div.flex.flex-col.space-y-4 > button.px-4.py-2.text-white.font-semibold.rounded-md.bg-purple-600.cursor-pointer.hover\\:bg-purple-700'
  8. try:
  9. # 等待输入框出现并确保其可交互
  10. page.wait_for_selector(input_selector, state='visible', timeout=10000)
  11. # 清除输入框内容(如果有默认值)
  12. page.fill(input_selector, '')
  13. # 填入钱包地址
  14. page.fill(input_selector, wallet_address)
  15. # 等待按钮出现并尝试点击,捕获异常以忽略找不到按钮的情况
  16. page.wait_for_selector(button_selector, state='visible', timeout=10000)
  17. try:
  18. page.click(button_selector)
  19. print(f"已成功点击按钮,查询钱包地址:{wallet_address}")
  20. except Exception as e:
  21. print(f"未找到按钮,跳过点击操作。钱包地址:{wallet_address}")
  22. except Exception as e:
  23. print(f"查询钱包 {wallet_address} 时出错: {str(e)}")
  24. def run():
  25. with sync_playwright() as p:
  26. browser = p.chromium.launch(
  27. headless=True,
  28. args=["--start-maximized"]
  29. )
  30. wallet_list = []
  31. wallet_txt_path = os.path.join(os.getcwd(), "wallet.txt")
  32. with open(wallet_txt_path, "r") as file:
  33. wallet_list = [line.strip() for line in file]
  34. if len(wallet_list) == 0:
  35. print("未找到钱包地址")
  36. return
  37. context = browser.new_context(no_viewport=True)
  38. for i, wallet in enumerate(wallet_list, 1):
  39. page = context.new_page()
  40. page.goto("https://repute.monadscore.xyz/")
  41. print(f"已打开第 {i} 个标签页")
  42. time.sleep(1)
  43. print(f'正在查询钱包 {i} : {wallet}')
  44. get_wallet_detail(wallet, page)
  45. time.sleep(3600)
  46. context.close()
  47. browser.close()
  48. def main():
  49. while True:
  50. run()
  51. time.sleep(5)
  52. if __name__ == "__main__":
  53. main()