You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.2 KiB
28 lines
1.2 KiB
import time
|
|
from playwright.sync_api import sync_playwright
|
|
|
|
def extract_content():
|
|
with sync_playwright() as p:
|
|
# 启动浏览器(无头)模式并设置代理
|
|
browser = p.chromium.launch(headless=True, proxy={"server": "http://127.0.0.1:7890"})
|
|
page = browser.new_page()
|
|
|
|
url = "https://app.galxe.com/quest/tiktrix/GCqaRtftKv"
|
|
page.goto(url)
|
|
|
|
page.wait_for_load_state()
|
|
|
|
time.sleep(5)
|
|
|
|
selector = r'body > div.flex.flex-col.flex-nowrap.min-h-dvh.relative.pb-\[66px\].sm\:pb-0 > main > div.flex-1.max-w-\[100vw\].w-full > section > div > div.flex.justify-between.flex-col.w-full.md\:flex-row.sm\:justify-center > div > div.flex.flex-col.px-0.sm\:mb-5.w-full.sm\:px-0.sm\:py-0.sm\:flex-row.sm\:justify-between.sm\:gap-\[72px\] > div > div.flex.gap-2.mt-4.sm\:mt-5.sm\:gap-4 > div.font-mona.flex-1.flex.items-center.line-clamp-2.text-size-20.sm\:text-size-28.mh-20.font-extrabold'
|
|
content_elements = page.query_selector_all(selector)
|
|
|
|
if content_elements:
|
|
for element in content_elements:
|
|
print(element.text_content())
|
|
|
|
# 关闭浏览器
|
|
browser.close()
|
|
|
|
if __name__ == "__main__":
|
|
extract_content() |