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

HTMLTokenizer.stream.chunkOffset not updating on string with no html elements #571

Open
ehsmeng opened this issue Jul 29, 2023 · 0 comments

Comments

@ehsmeng
Copy link

ehsmeng commented Jul 29, 2023

from html5lib._tokenizer import HTMLTokenizer
from io import StringIO

class T():
    def __init__(self, data):
        print("Object from string: " + data)
        self.src = StringIO()
        self.tokenizer = HTMLTokenizer(self.src)

        pos = self.src.tell()
        self.src.write(data)
        self.src.seek(pos)
        self.handle_tokens()
        self.src.close()

    def handle_tokens(self):
        for token in self.tokenizer:
            print(str(self.tokenizer.stream.chunkOffset))

T("klas katt")
T("klas katt<br>")

->

Object from string: klas katt
0
Object from string: klas katt

9
13

I expected first number outputted to be 9.

Apologies if this is an internal variable I should not use.
I'm trying to deduce tag offsets (start,stop) in the html document.

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

1 participant