dhtmlparser3.tags.tag

class dhtmlparser3.tags.tag.Tag(name, parameters=None, content=None, is_non_pair=False)[source]

Bases: object

name

Name of the parsed tag.

Type:str
parameters

Dictionary for the parameters.

Type:SpecialDict
content

List of sub-elements.

Type:list
parent

Reference to parent element.

Type:Tag
p

Shortcut for .parameters, used extensively in tests.

c

Shortcut for .content, used extensively in tests.

tags

Same as .c, but returns only tag instances. Useful for ignoring whitespace and comment clutter and iterating over the real dom structure.

Make the DOM hierarchy double-linked. Each content element now points to the parent element.

content_without_tags() → str[source]

Return content but remove all tags.

This is sometimes useful for processing messy websites.

remove(offending_item: Union[str, Tag, dhtmlparser3.tags.comment.Comment]) → bool[source]

Remove offending_item anywhere from the dom.

Item is matched using is operator, so it better be something you’ve found using .find() or other relevant methods.

Returns:True if the item was found and removed.
Return type:bool
remove_item(item: Union[str, Tag, dhtmlparser3.tags.comment.Comment])[source]

Remove the item from the .content property.

If the item is Tag instance, match it using tag name and parameters.

to_string() → str[source]

Get HTML representation of the tag and the content.

tag_to_str() → str[source]

Convert just the tag with parameters to string, without content.

content_str() → str[source]

Return everything in between the tags as string.

replace_with(item: dhtmlparser3.tags.tag.Tag, keep_content=True)[source]
wfind(name, p=None, fn=None, case_sensitive=False)[source]
match(*args)[source]
find(name, p=None, fn=None, case_sensitive=False) → List[dhtmlparser3.tags.tag.Tag][source]
findb(name, p=None, fn=None, case_sensitive=False) → List[dhtmlparser3.tags.tag.Tag][source]
find_depth_first_iter(name, p=None, fn=None, case_sensitive=False) → Iterator[dhtmlparser3.tags.tag.Tag][source]
find_breadth_first_iter(name, p=None, fn=None, case_sensitive=False) → Iterator[dhtmlparser3.tags.tag.Tag][source]
depth_first_iterator(tags_only=False) → Iterator[Union[dhtmlparser3.tags.tag.Tag, str, dhtmlparser3.tags.comment.Comment]][source]
breadth_first_iterator(tags_only=False, _first_call=True) → Iterator[Union[dhtmlparser3.tags.tag.Tag, str, dhtmlparser3.tags.comment.Comment]][source]
prettify(depth=0, dont_format=False) → str[source]