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

Class Xpath_prompter

module/prompt.py:11–201  ·  view source on GitHub ↗

_summary_

Source from the content-addressed store, hash-verified

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
11class 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
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

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected