Skip to content

Commit

Permalink
update shop.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fllesser committed Jan 8, 2025
1 parent 1e40fc6 commit 7200864
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions nonebot_plugin_fortnite/shop.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ async def screenshot_shop_img() -> Path:

async with async_playwright() as p:
try:
browser = await p.chromium.launch(headless=True) # 启动无头模式的 Chromium 浏览器
page = await browser.new_page()
browser = await p.chromium.launch(headless=False) # 使用无头模式可能会被检测到,建议使用有头模式
context = await browser.new_context()
page = await context.new_page()

# 设置用户代理
await context.set_user_agent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")

# 设置浏览器参数
await context.add_init_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")

# browser = await p.chromium.launch(headless=True) # 启动无头模式的 Chromium 浏览器
# page = await browser.new_page()
await page.goto('https://www.fortnite.com/item-shop?lang=zh-Hans', timeout=60000) # 增加超时时间
await page.wait_for_load_state('networkidle') # 等待页面加载完成
await page.screenshot(path=shop_file, full_page=True) # 截取整个页面
Expand All @@ -24,3 +34,4 @@ async def screenshot_shop_img() -> Path:
await browser.close()

return shop_file

0 comments on commit 7200864

Please sign in to comment.