Skip to content

爬蟲處理JS網頁的問題 #6

Answered by jwlin
philosopher1121 asked this question in Q&A
Discussion options

You must be logged in to vote

我不太了解問題的內容,但如果只是要用 playwright 去進行抽獎動作,就用 playwright codegen 錄製過程,再找尋可以定位抽獎結果資訊的標籤即可。以下是我測試的抽獎動作及執行截圖,有回答到你的問題嗎?

from playwright.sync_api import Playwright, sync_playwright, expect


def run(playwright: Playwright) -> None:
    browser = playwright.chromium.launch(headless=False)
    context = browser.new_context()
    page = context.new_page()
    page.goto("https://www.burgerking.com.tw/")
    page.get_by_role("button", name="GO").click()
    print(page.locator(".player-styles-opnfk-1ec2byg").text_content())
    print(page.locator(".player-styles-opnfk-796bk7").text_content())


    # ---------------------
    context.close()
    browser.close()


with sync_playwright() as playwright:
    

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@philosopher1121
Comment options

@philosopher1121
Comment options

@jwlin
Comment options

Answer selected by jwlin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants