Skip to content
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

Pass LXML object straight to readability? #140

Open
adbar opened this issue Feb 18, 2020 · 2 comments
Open

Pass LXML object straight to readability? #140

adbar opened this issue Feb 18, 2020 · 2 comments

Comments

@adbar
Copy link

adbar commented Feb 18, 2020

As of now only strings containing HTML seem to be acceptable input.

Is there a way to pass an object parsed by LXML or lxml.html (types: etree._ElementTree and html.HtmlElement) straight to Document() or should we create one?

@buriy
Copy link
Owner

buriy commented Feb 18, 2020

The library changes the lxml document internally, that's why I would avoid that in a public version.
When you're warned, you can now subclass Document and replace _parse method the behavior you need, e.g.

    def _parse(self, input):
        return input

or

    def _parse(self, input):
        return convert_and_deepcopy(input)

Then just use
doc = Document(your_tree)

You can also make a PR which does that --checks for an input type and makes a copy of lxml document passed if it's an lxml document (or an etree document).

@adbar
Copy link
Author

adbar commented Feb 19, 2020

Thanks for the answer, I added a bypass to PR #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants