此脚本仅给予错误ref: <Node>
from playwright.sync_api import Playwright, sync_playwright, expect
import time
def run(playwright: Playwright) -> None:
browser = playwright.firefox.launch(headless=False)
context = browser.new_context()
page = context.new_page()
page.goto("https://url")
page.get_by_role("button", name="I understand").click()
page.get_by_placeholder("Type a message").fill("hello")
page.locator("form").get_by_role("button").first.click()
time.sleep(10) #Waiting, because the output text is still rendering
output_text = page.query_selector('.char-msg').json_value()
print(output_text)
# ---------------------
context.close()
browser.close()
with sync_playwright() as playwright:
run(playwright)
如何找到特定的div类,并在渲染/加载时打印文本?
位于中的输出文本
<div class="msg char-msg"><div style="max-width: 100%;"><div class="markdown-wrapper markdown-wrapper-last-msg swiper-no-swiping"><div style="overflow-wrap: break-word;"><p>This is the output text</p></div></div></div><div></div></div>
我找不到特定div类之后的输出文本,在呈现文本时,它应该会给予我一个输出,但输出只给我一个错误ref: <Node>
1条答案
按热度按时间fcwjkofz1#
通过更改此
到这个