_summary_
| 9 | self.role_prompt = "Suppose you're a web parser that is good at reading and understanding the HTML code and can give clear executable code on the brower." |
| 10 | |
| 11 | class Xpath_prompter(Base_prompter): |
| 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 | |
| 19 | Instruction: {0} |
| 20 | |
| 21 | Here're some hints: |
| 22 | 1. Do not output the xpath with exact value or element appears in the HTML. |
| 23 | 2. 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. |
| 24 | 3. If the HTML code doesn't contain the suitable information match the instruction, keep the xpath attrs blank. |
| 25 | 4. Avoid using some string function such as 'substring()' and 'normalize-space()' to normalize the text in the node. |
| 26 | Please 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 | }} |
| 33 | Here'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 | |
| 41 | Instruction: {0} |
| 42 | The element value: {1} |
| 43 | |
| 44 | Here're some hints: |
| 45 | 1. Do not output the xpath with exact value or element appears in the HTML. |
| 46 | 2. 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. |
| 47 | 3. If the HTML code doesn't contain the suitable information match the instruction, keep the xpath attrs blank. |
| 48 | 4. Avoid using some string function such as 'substring()' and 'normalize-space()' to normalize the text in the node. |
| 49 | Please 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 | }} |
| 55 | Here's the HTML code: |
| 56 | ``` |
| 57 | {2} |
| 58 | ``` |
| 59 | ''' |
| 60 | # 针对Xpath和单网页修改并生成对应正确的Xpath |
| 61 | self.reflection_prompt = '''Here's the HTML extraction task: |
| 62 | Task description: Please read the following HTML code, and then return an Xpath that can recognize the element in the HTML matching the instruction below. |
| 63 | Instruction: {0} |
| 64 | |
| 65 | We 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: |
| 66 | 1. 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 |