Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

AttributeError: 'unicode' object has no attribute 'tag' #115

Closed
Milestone
@aleray

Description

@aleray

Hi,

I'm facing an issue with this code: "AttributeError: 'unicode' object has no attribute 'tag'"

importhtml5libparser=html5lib.HTMLParser(tree=html5lib.treebuilders.getTreeBuilder("lxml"),namespaceHTMLElements=False)serializer=html5lib.serializer.HTMLSerializer(omit_optional_tags=False)walker=html5lib.treewalkers.getTreeWalker("lxml")# workssrc=u"experiences"tree=parser.parseFragment(src,container="div")stream=walker(tree)output=serializer.serialize(stream)print("\n".join(output))# Doesn't worksrc=u"exp\xe9riences"tree=parser.parseFragment(src,container="div")stream=walker(tree)output=serializer.serialize(stream)print("\n".join(output))

I think the error lies in theisstring method ofFragmentWrapper class in treewalker/lxmletree.py

Changing:

defensure_str(s):ifsisNone:returnNoneelifisinstance(s,text_type):returnselse:returns.decode("utf-8","strict")classFragmentWrapper(object):def__init__(self,fragment_root,obj):        ...self.isstring=isinstance(obj,str)orisinstance(obj,bytes)# Support for bytes here is Py2ifself.isstring:self.obj=ensure_str(self.obj)

to

defensure_str(s):ifsisNone:returnNoneelifisinstance(s,text_type):returnselse:returns.decode("utf-8","strict")classFragmentWrapper(object):def__init__(self,fragment_root,obj):        ...self.isstring=isinstance(obj,str)orisinstance(obj,bytes)orisinstance(obj,text_type)# Support for bytes here is Py2ifself.isstring:self.obj=ensure_str(self.obj)

seems to do the job... What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp