【问题标题】:I am trying to store a html table into a pandas dataframe. But I am getting an error, TypeError: Cannot read object of type 'WebElement'我正在尝试将 html 表存储到 pandas 数据框中。但我收到一个错误,TypeError: Cannot read object of type 'WebElement'
【发布时间】:2020-02-17 04:58:18
【问题描述】:

我正在尝试将 html 表存储到 pandas 数据框中。但我收到一个错误TypeError: Cannot read object of type 'WebElement'

    driver.get('web_url')
    driver.maximize_window()
    driver.find_element_by_xpath('//tbody[@id = "treeview-1083-body"]//tr[@id = "treeview-1083-record-ext-record-20"]').click()
    time.sleep(4)
    recording_table = driver.find_element_by_id("table_id")
    df = pd.read_html(recording_table)
    print(df)

【问题讨论】:

标签: python html selenium


【解决方案1】:

pandas.read_html 函数可以从 URL、类似文件的对象或包含 HTML 而非 WebElement 的原始字符串中读取 HTML。

您可以尝试将此元素转换为原始字符串。 为此,您可以获取外部 HTML

content = recording_table.get_attribute("outerHTML")
pd.read_html(content)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-09-20
    • 2023-02-22
    • 2021-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-20
    • 1970-01-01
    相关资源
    最近更新 更多