Search code examples
pythonplaywrightplaywright-python

How to get outer html from python playwright locator object?


I could not find any method that returns outer html from python playwright page.locator(selector, **kwargs). Am I missing something? locator.inner_html(**kwargs) do exists. However, I am trying to use pandas.read_html and it fails on table locator inner html as it trips table tag.

What I'm currently doing is using bs4 to parse page.content(). something like:

soup = BeautifulSoup(page.content(), 'lxml')
df = pd.read_html(str(soup.select('table.selector')))

Solution

  • There is no outer_html out of the box. But it's not hard to implement it:

    locator.evaluate("el => el.outerHTML")