OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Python Playwright automation with tables

  • Thread starter Thread starter user25656993
  • Start date Start date
U

user25656993

Guest
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

Code:
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()
<p>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</p>
<p>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.</p>
<p>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</p>
<pre><code>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()
</code></pre>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top