.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.utils._HTMLTextExtractor Class Reference
+ Inheritance diagram for searx.utils._HTMLTextExtractor:
+ Collaboration diagram for searx.utils._HTMLTextExtractor:

Public Member Functions

 __init__ (self)
 
 handle_starttag (self, tag, attrs)
 
 handle_endtag (self, tag)
 
 is_valid_tag (self)
 
 handle_data (self, data)
 
 handle_charref (self, name)
 
 handle_entityref (self, name)
 
 get_text (self)
 
 error (self, message)
 

Public Attributes

list result = []
 
list tags = []
 

Detailed Description

Internal class to extract text from HTML

Definition at line 84 of file utils.py.

Constructor & Destructor Documentation

◆ __init__()

searx.utils._HTMLTextExtractor.__init__ ( self)

Definition at line 87 of file utils.py.

87 def __init__(self):
88 HTMLParser.__init__(self)
89 self.result = []
90 self.tags = []
91

Member Function Documentation

◆ error()

searx.utils._HTMLTextExtractor.error ( self,
message )

Definition at line 133 of file utils.py.

133 def error(self, message):
134 # error handle is needed in <py3.10
135 # https://github.com/python/cpython/pull/8562/files
136 raise AssertionError(message)
137
138

◆ get_text()

searx.utils._HTMLTextExtractor.get_text ( self)

Definition at line 130 of file utils.py.

130 def get_text(self):
131 return ''.join(self.result).strip()
132

References searx.utils._HTMLTextExtractor.result.

◆ handle_charref()

searx.utils._HTMLTextExtractor.handle_charref ( self,
name )

Definition at line 114 of file utils.py.

114 def handle_charref(self, name):
115 if not self.is_valid_tag():
116 return
117 if name[0] in ('x', 'X'):
118 codepoint = int(name[1:], 16)
119 else:
120 codepoint = int(name)
121 self.result.append(chr(codepoint))
122

References searx.utils._HTMLTextExtractor.is_valid_tag(), and searx.utils._HTMLTextExtractor.result.

+ Here is the call graph for this function:

◆ handle_data()

searx.utils._HTMLTextExtractor.handle_data ( self,
data )

Definition at line 109 of file utils.py.

109 def handle_data(self, data):
110 if not self.is_valid_tag():
111 return
112 self.result.append(data)
113

References searx.utils._HTMLTextExtractor.is_valid_tag(), and searx.utils._HTMLTextExtractor.result.

+ Here is the call graph for this function:

◆ handle_endtag()

searx.utils._HTMLTextExtractor.handle_endtag ( self,
tag )

Definition at line 97 of file utils.py.

97 def handle_endtag(self, tag):
98 if not self.tags:
99 return
100
101 if tag != self.tags[-1]:
102 raise _HTMLTextExtractorException()
103
104 self.tags.pop()
105

References searx.utils._HTMLTextExtractor.tags.

◆ handle_entityref()

searx.utils._HTMLTextExtractor.handle_entityref ( self,
name )

Definition at line 123 of file utils.py.

123 def handle_entityref(self, name):
124 if not self.is_valid_tag():
125 return
126 # codepoint = htmlentitydefs.name2codepoint[name]
127 # self.result.append(chr(codepoint))
128 self.result.append(name)
129

References searx.utils._HTMLTextExtractor.is_valid_tag(), and searx.utils._HTMLTextExtractor.result.

+ Here is the call graph for this function:

◆ handle_starttag()

searx.utils._HTMLTextExtractor.handle_starttag ( self,
tag,
attrs )

Definition at line 92 of file utils.py.

92 def handle_starttag(self, tag, attrs):
93 self.tags.append(tag)
94 if tag == 'br':
95 self.result.append(' ')
96

References searx.utils._HTMLTextExtractor.result, and searx.utils._HTMLTextExtractor.tags.

◆ is_valid_tag()

searx.utils._HTMLTextExtractor.is_valid_tag ( self)

Definition at line 106 of file utils.py.

106 def is_valid_tag(self):
107 return not self.tags or self.tags[-1] not in _BLOCKED_TAGS
108

References searx.utils._HTMLTextExtractor.tags.

Referenced by searx.utils._HTMLTextExtractor.handle_charref(), searx.utils._HTMLTextExtractor.handle_data(), and searx.utils._HTMLTextExtractor.handle_entityref().

+ Here is the caller graph for this function:

Member Data Documentation

◆ result

◆ tags

list searx.utils._HTMLTextExtractor.tags = []

The documentation for this class was generated from the following file: