MCPcopy Create free account
hub / github.com/EZ-hwh/AutoScraper / generate_sequence_html

Method generate_sequence_html

module/stepback_crawler.py:138–221  ·  view source on GitHub ↗
(self,
                          instruction: str,
                          html_content: str,
                          ground_truth=None)

Source from the content-addressed store, hash-verified

136 return {key:"" for key in keys}
137
138 def generate_sequence_html(self,
139 instruction: str,
140 html_content: str,
141 ground_truth=None):
142
143 action_sequence = []
144
145 for _ in range(5):
146 print(len(html_content))
147 # Generate xpath & result
148 if ground_truth:
149 query = f'{role_prompt}/n{crawler_wr_prompt.format(instruction, ground_truth, html_content)}'
150 res = self.request_parse(query, ['thought', 'xpath'])
151
152 # Extract with xpath
153 results = self.extract_with_xpath(html_content, res['xpath'])
154 value = ground_truth
155 xpath = res['xpath']
156
157 print('-' * 50)
158 print(value)
159 print(results)
160 print(xpath)
161
162 if value == '':
163 return action_sequence
164
165 query = f'{role_prompt}/n{judgement_prompt.format(str(results), value)}'
166
167 res = self.request_parse(query, ['thought', 'judgement'])
168
169 print(json.dumps(res, ensure_ascii=False, indent=4))
170 if res['judgement'].lower() == 'yes':
171 action_sequence.append(xpath)
172 return action_sequence
173 else:
174 query = f'{role_prompt}/n{crawler_prompt.format(instruction, html_content)}'
175 res = self.request_parse(query, ['thought', 'value', 'xpath'])
176
177 # Extract with xpath
178 results = self.extract_with_xpath(html_content, res['xpath'])
179 value = res['value']
180 xpath = res['xpath']
181
182 print('-' * 50)
183 print(value)
184 print(results)
185 print(xpath)
186
187 if value == '':
188 return action_sequence
189
190 query = f'{role_prompt}/n{judgement_prompt.format(str(results), value)}'
191
192 res = self.request_parse(query, ['thought', 'judgement'])
193
194 print(json.dumps(res, ensure_ascii=False, indent=4))
195 if res['judgement'].lower() == 'yes':

Callers 2

generate_sequenceMethod · 0.95
generate_ruleMethod · 0.80

Calls 3

request_parseMethod · 0.95
extract_with_xpathMethod · 0.95
find_common_ancestorFunction · 0.90

Tested by

no test coverage detected