【问题标题】:How to get outer html from python playwright locator object?如何从 python playwright 定位器对象获取外部 html?
【发布时间】:2022-01-28 20:22:24
【问题描述】:

我找不到任何从 python playwright page.locator(selector, **kwargs) 返回外部 html 的方法。 我错过了什么吗? locator.inner_html(**kwargs) 确实存在。但是,我正在尝试使用 pandas.read_html,但它在表定位器内部 html 上失​​败,因为它会触发表标记。

我目前正在做的是使用 bs4 来解析 page.content()。 类似:

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

【问题讨论】:

    标签: python playwright playwright-python


    【解决方案1】:

    没有开箱即用的outer_html。但是实现起来并不难:

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

    【讨论】:

      猜你喜欢
      • 2017-02-16
      • 2021-01-16
      • 1970-01-01
      • 1970-01-01
      • 2010-12-21
      • 2012-08-08
      • 1970-01-01
      • 2021-09-01
      相关资源
      最近更新 更多