async_monadscore_query.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import os
  2. from playwright.sync_api import sync_playwright
  3. from screeninfo import get_monitors
  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 main():
  25. # 读取钱包地址
  26. wallet_list = []
  27. wallet_txt_path = os.path.join(os.getcwd(), "wallet.txt")
  28. with open(wallet_txt_path, "r") as file:
  29. wallet_list = [line.strip() for line in file]
  30. if len(wallet_list) == 0:
  31. print("未找到钱包地址,程序退出。")
  32. return
  33. if len(wallet_list) > 10:
  34. print("钱包地址数量超过10个,仅处理前10个。")
  35. wallet_list = wallet_list[:10]
  36. # 获取屏幕大小
  37. monitors = get_monitors()
  38. screen_width = monitors[0].width
  39. screen_height = monitors[0].height
  40. # 每个窗口的大小
  41. window_width = screen_width // 5
  42. window_height = screen_height // 2
  43. with sync_playwright() as p:
  44. browser = p.chromium.launch(headless=False, args=["--start-maximized"])
  45. for i, wallet in enumerate(wallet_list):
  46. # 计算窗口位置
  47. row = i // 5
  48. col = i % 5
  49. x = col * window_width
  50. y = row * window_height
  51. # 创建新页面并设置窗口位置
  52. context = browser.new_context()
  53. page = context.new_page()
  54. page.set_viewport_size({'width': window_width, 'height': window_height})
  55. page.context.set_window_position(x, y)
  56. page.goto("https://repute.monadscore.xyz/")
  57. print(f"已打开浏览器实例,查询钱包地址:{wallet}")
  58. get_wallet_detail(wallet, page)
  59. print("所有浏览器已打开,可以手动操作。")
  60. input("按任意键退出程序...")
  61. # 关闭浏览器
  62. browser.close()
  63. if __name__ == "__main__":
  64. main()