7

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')))

1 Answer 1

13

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

locator.evaluate("el => el.outerHTML") 
Sign up to request clarification or add additional context in comments.

1 Comment

could be an idea to add an out of the box way. I instictively tried await locator.content(), which bugged but your solution works perfectly. tx a lot

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.