I can’t figure out how to get this code to work. The unique locator (using letxpath) is table[contains(@class, ‘whole data-table’)] the CSS path is tr#whole.detail.information>td:nth-of-type(3)>div
I can’t provide the website for the table. The website dynamically updates. I either want to save the whole table as a dictionary and access it with elements. or just access the rows of the table I need, and access those columns with indexes.
For some reason it’s not saving the table to the dictionary and it’s not working. I believe it has to do something with the page locator line
from playwright.sync_api import sync_playwright # 1.44.0
with sync_playwright() as p:
browser = p.chromium.launch(headless=False)
page = browser.new_page()
url = "XXXX"
page.goto(url, wait_until="domcontentloaded")
result = page.locator("whole data-table tr").evaluate_all("""
rows => rows.map(row =>
[...row.querySelectorAll("td, th")]
.map(cell => cell.textContent.trim())
)"""
)
browser.close()
user25656993 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.