常量
本节记录了 Pydoll 中使用的所有常量、枚举和配置值。
pydoll.constants
By
Bases: str
, Enum
Scripts
ELEMENT_VISIBLE
class-attribute
instance-attribute
ELEMENT_VISIBLE = "\n function() {\n const rect = this.getBoundingClientRect();\n return (\n rect.width > 0 && rect.height > 0\n && getComputedStyle(this).visibility !== 'hidden'\n && getComputedStyle(this).display !== 'none'\n )\n }\n "
ELEMENT_ON_TOP
class-attribute
instance-attribute
ELEMENT_ON_TOP = '\n function() {\n const rect = this.getBoundingClientRect();\n const x = rect.x + rect.width / 2;\n const y = rect.y + rect.height / 2;\n const elementFromPoint = document.elementFromPoint(x, y);\n if (!elementFromPoint) {\n return false;\n }\n return elementFromPoint === this || this.contains(elementFromPoint);\n }\n '
ELEMENT_INTERACTIVE
class-attribute
instance-attribute
ELEMENT_INTERACTIVE = "\n function() {\n const style = window.getComputedStyle(this);\n const rect = this.getBoundingClientRect();\n if (\n rect.width <= 0 ||\n rect.height <= 0 ||\n style.visibility === 'hidden' ||\n style.display === 'none' ||\n style.pointerEvents === 'none'\n ) {\n return false;\n }\n const x = rect.x + rect.width / 2;\n const y = rect.y + rect.height / 2;\n const elementFromPoint = document.elementFromPoint(x, y);\n if (!elementFromPoint || (elementFromPoint !== this && !this.contains(elementFromPoint))) {\n return false;\n }\n if (this.disabled) {\n return false;\n }\n return true;\n }\n "
CLICK
class-attribute
instance-attribute
CLICK = "\n function(){\n clicked = false;\n this.addEventListener('click', function(){\n clicked = true;\n });\n this.click();\n return clicked;\n }\n "
CLICK_OPTION_TAG
class-attribute
instance-attribute
CLICK_OPTION_TAG = "\n function() {\n this.selected = true;\n var select = this.parentElement.closest('select');\n var event = new Event('change', { bubbles: true });\n select.dispatchEvent(event);\n }\n "
BOUNDS
class-attribute
instance-attribute
FIND_RELATIVE_XPATH_ELEMENT
class-attribute
instance-attribute
FIND_RELATIVE_XPATH_ELEMENT = '\n function() {\n return document.evaluate(\n "{escaped_value}", this, null,\n XPathResult.FIRST_ORDERED_NODE_TYPE, null\n ).singleNodeValue;\n }\n '
FIND_XPATH_ELEMENT
class-attribute
instance-attribute
FIND_XPATH_ELEMENT = '\n var element = document.evaluate(\n "{escaped_value}", document, null,\n XPathResult.FIRST_ORDERED_NODE_TYPE, null\n ).singleNodeValue;\n element;\n '
FIND_RELATIVE_XPATH_ELEMENTS
class-attribute
instance-attribute
FIND_RELATIVE_XPATH_ELEMENTS = '\n function() {\n var elements = document.evaluate(\n "{escaped_value}", this, null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null\n );\n var results = [];\n for (var i = 0; i < elements.snapshotLength; i++) {\n results.push(elements.snapshotItem(i));\n }\n return results;\n }\n '
FIND_XPATH_ELEMENTS
class-attribute
instance-attribute
FIND_XPATH_ELEMENTS = '\n var elements = document.evaluate(\n "{escaped_value}", document, null,\n XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null\n );\n var results = [];\n for (var i = 0; i < elements.snapshotLength; i++) {\n results.push(elements.snapshotItem(i));\n }\n results;\n '
QUERY_SELECTOR
class-attribute
instance-attribute
RELATIVE_QUERY_SELECTOR
class-attribute
instance-attribute
QUERY_SELECTOR_ALL
class-attribute
instance-attribute
RELATIVE_QUERY_SELECTOR_ALL
class-attribute
instance-attribute
RELATIVE_QUERY_SELECTOR_ALL = '\n function() {\n return this.querySelectorAll("{selector}");\n }\n '
GET_PARENT_NODE
class-attribute
instance-attribute
MAKE_REQUEST
class-attribute
instance-attribute
MAKE_REQUEST = '\n(async function() {{\n async function makeRequest(url, options) {{\n try {{\n const response = await fetch(url, options, {{\n credentials: \'include\',\n }});\n const headers = {{}};\n response.headers.forEach((value, key) => {{\n headers[key] = value;\n }});\n\n // Extract cookies from set-cookie header\n const cookies = document.cookie;\n let text = await response.text();\n const possiblePrefixes = [")]}}\'\\n", ")]}}\'\\n", ")]}}\\n"];\n for (let prefix of possiblePrefixes) {{\n if (text.startsWith(prefix)) {{\n text = text.substring(prefix.length);\n break;\n }}\n }}\n let content, jsonData;\n const contentType = response.headers.get(\'content-type\') || \'\';\n\n if (contentType.includes(\'application/json\')) {{\n try {{\n jsonData = JSON.parse(text);\n text = JSON.stringify(jsonData);\n }} catch (e) {{\n jsonData = null;\n // Keep original text if parsing fails\n }}\n content = new TextEncoder().encode(text).buffer;\n }} else {{\n // For non-JSON, keep original text handling\n content = new TextEncoder().encode(text).buffer;\n jsonData = null;\n }}\n\n return {{\n status: response.status,\n ok: response.ok,\n url: response.url,\n headers: headers,\n cookies: cookies,\n content: Array.from(new Uint8Array(content)),\n text: text,\n json: jsonData\n }};\n }} catch (error) {{\n return {{\n error: error.toString(),\n status: 0\n }};\n }}\n }}\n\n const url = {url};\n const options = {options};\n return await makeRequest(url, options);\n}})();\n'
Key
Bases: tuple[str, int]
, Enum