Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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')))
like image 895
Rahul Avatar asked Jul 18 '26 17:07

Rahul


1 Answers

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

locator.evaluate("el => el.outerHTML") 
like image 174
hardkoded Avatar answered Jul 21 '26 14:07

hardkoded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!