Skip to content

BUG: read_html reads <style> element text #52197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
m-ganko opened this issue Mar 25, 2023 · 1 comment · Fixed by #52251
Closed
3 tasks done

BUG: read_html reads <style> element text #52197

m-ganko opened this issue Mar 25, 2023 · 1 comment · Fixed by #52251
Assignees
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap

Comments

@m-ganko
Copy link
Contributor

m-ganko commented Mar 25, 2023

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import pandas as pd

html_table = """
<table>
    <tr>
        <th>
            <style>.style</style>
            A
            </th>
        <th>B</th>
    </tr>
    <tr>
        <td>A1</td>
        <td>B1</td>
    </tr>
    <tr>
        <td>A2</td>
        <td>B2</td>
    </tr>
</table>
"""
pd.read_html(html_table)[0]

  .style  A   B
0        A1  B1
1        A2  B2

Issue Description

When table cell contains <style> element pandas reads it into DataFrame.

Expected Behavior

I think in most cases we don't want this behavior. I propose to control this using existing argument displayed_only (since <style> element is not displayed) or adding new one e.g. skip_style_elements.

Installed Versions

'2.1.0.dev0+280.g0755f22017.dirty'
@m-ganko m-ganko added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 25, 2023
@phofl phofl added IO HTML read_html, to_html, Styler.apply, Styler.applymap and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Mar 25, 2023
@zbreger
Copy link
Contributor

zbreger commented Mar 26, 2023

take

zbreger added a commit to zbreger/pandas that referenced this issue Mar 27, 2023
zbreger added a commit to zbreger/pandas that referenced this issue Mar 27, 2023
… in the DataFrame. When these style elements are encountered upon parsing, the trees rooted in these elements are dropped.
@zbreger zbreger mentioned this issue Mar 27, 2023
5 tasks
mroeschke pushed a commit that referenced this issue Mar 28, 2023
* #52197 bug fix. These styling details aren't intended to be in the DataFrame. When these style elements are encountered upon parsing, the trees rooted in these elements are dropped.

* Removing extraneous line used for testing

* Added an entry in the latest doc file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO HTML read_html, to_html, Styler.apply, Styler.applymap
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants