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

Method __init__

module/prompt.py:14–201  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

12 """_summary_
13 """
14 def __init__(self) -> None:
15 super().__init__()
16 # 用于第一次生成xpath
17 self.crawler_prompt = '''Please read the following HTML code, and then return an Xpath that can recognize the element in the HTML matching the instruction below.
18
19Instruction: {0}
20
21Here're some hints:
221. Do not output the xpath with exact value or element appears in the HTML.
232. Do not output the xpath that indicate multi node with different value. It would be appreciate to use more @class to identify different node that may share the same xpath expression.
243. If the HTML code doesn't contain the suitable information match the instruction, keep the xpath attrs blank.
254. Avoid using some string function such as 'substring()' and 'normalize-space()' to normalize the text in the node.
26Please output in the following Json format:
27
28{{
29 "thought": "", # a brief thought of how to confirm the value and generate the xpath
30 "value": "", # the value extracted from the HTML that match the instruction
31 "xpath": "", # the xpath to extract the value
32}}
33Here's the HTML code:
34```
35{1}
36```
37'''
38
39 self.crawler_wr_prompt = '''Please read the following HTML code, and then return an Xpath that can recognize the element in the HTML matching the instruction below.
40
41Instruction: {0}
42The element value: {1}
43
44Here're some hints:
451. Do not output the xpath with exact value or element appears in the HTML.
462. Do not output the xpath that indicate multi node with different value. It would be appreciate to use more @class to identify different node that may share the same xpath expression.
473. If the HTML code doesn't contain the suitable information match the instruction, keep the xpath attrs blank.
484. Avoid using some string function such as 'substring()' and 'normalize-space()' to normalize the text in the node.
49Please output in the following Json format:
50
51{{
52 "thought": "", # a brief thought of how to generate the xpath
53 "xpath": "", # the xpath to extract the value
54}}
55Here's the HTML code:
56```
57{2}
58```
59'''
60 # 针对Xpath和单网页修改并生成对应正确的Xpath
61 self.reflection_prompt = '''Here's the HTML extraction task:
62Task description: Please read the following HTML code, and then return an Xpath that can recognize the element in the HTML matching the instruction below.
63Instruction: {0}
64
65We will offer some history about the thought and the extraction result. Please reflect on the history trajectory and adjust the xpath rule for better and more exact extraction. Here's some hints:
661. Judge whether the results in the history is consistent with the expected value. Please pay attention for the following case:
67 1) Whether the extraction result contains some elements that is irrelevent
68 2) Whether the crawler return a empty result
69 3) The raw values containing redundant separators is considered as consistent because we will postprocess it.
702. Re-thinking the expected value and how to find it depend on xpath code
713. Generate a new or keep the origin xpath depend on the judgement and thinking following the hints:

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected