humanemulator.net — справка.
Продукт, демо и покупка — на
хуманэмулятор.рф
|
Демо
|
Купить
|
API
|
лог изменений
get_all_by_href
get_all_by_href($href,$exactly=false,$frame=-1); - данная функция используется для получения списка DOM интерфейсов элементов страницы, находя их по заданному href.Доступна с версии 4.6.34
Функция на вход принимает параметры:
С версии 4.6.41 достпуно: можно передавать вложенные фреймы, принцип такой же самый, передается строка с номерами фреймов, разделенных : например при передаче "1:0:5" - будет выбран фрейм с номером 1 в нем под фрейм с номером 0 и в нем подфрейм с номером 5
С версии 7.0.38 достпуно: можно передавать "url=>XXX", тогда будет произведен поиск фрейма, который содержит заданнй src, или передавать "name=>XXX" - тогда будет поиск фрейма, по заданной части имени.
После отработки функция возвращает результат своей работы в скрипт :
Пример использования
<?php // Scenario: Examples of using get_all_by_href function to retrieve multiple DOM elements by their href attribute // Path to init.php file for connecting to XHE API $xhe_host = "localhost:7010"; if (!isset($path)){ // Path to the init.php file for connecting to the XHE API $path = "../../../Templates/init.php"; // Including init.php grants access to all classes and functionality for working with the XHE API require($path); } // Navigate to a webpage with various elements $navigateResult = WEB::$browser->navigate(TEST_POLYGON_URL . "anchor.html"); // Check if navigation was successful if ($navigateResult) { echo "Successfully navigated to anchor.html\n"; // Wait for the page to load $waitResult = WEB::$browser->wait_for(); if ($waitResult) { echo "Page loaded successfully\n"; echo "\n\n=== Examples of using get_all_by_href function ===\n\n"; // Example 1: Get anchors by exact href match $href = "https://example.com/mouseover1"; $anchors = DOM::$anchor->get_all_by_href($href, true); // Check if the operation was successful if ($anchors) { echo "Successfully retrieved anchors with exact href '{$href}'\n"; // Get count of anchors $count = $anchors->get_count(); echo "\n\nTotal anchors found with exact href '{$href}': {$count}"; // Example 2: Iterate through retrieved anchors and display their details echo "\n\nIterating through anchors with exact href '{$href}':"; for ($k = 0; $k < $count; $k++) { $targetAnchor = $anchors->get($k); if ($targetAnchor !== false && $targetAnchor->is_exist()) { echo "\nanchor #{$k}:"; $id = $targetAnchor->get_id(); if ($id) { echo "\n ID: " . $id; } else { echo "\n Failed to get ID"; } $hrefAttr = $targetAnchor->get_href(); if ($hrefAttr) { echo "\n Href: " . $hrefAttr; } else { echo "\n Failed to get href"; } $innerText = $targetAnchor->get_inner_text(); if ($innerText) { echo "\n Inner text: " . $innerText; } else { echo "\n Failed to get inner text"; } } else { echo "\nFailed to get anchor #{$k}"; } } } else { echo "Failed to retrieve anchors with exact href '{$href}'\n"; } // Example 3: Get anchors by partial href match $href = "https://example.com/"; $anchors = DOM::$anchor->get_all_by_href($href, false); // exactly = false for partial match // Check if the operation was successful if ($anchors->get_count() > 0) { echo "\n\nSuccessfully retrieved anchors with partial href '{$href}'\n"; // Get count of anchors $count = $anchors->get_count(); echo "\n\nTotal anchors found with partial href '{$href}': {$count}"; // Example 4: Iterate through anchors with partial href match echo "\n\nIterating through anchors with partial href '{$href}':"; for ($k = 0; $k < $count; $k++) { $targetAnchor = $anchors->get($k); if ($targetAnchor !== false && $targetAnchor->is_exist()) { echo "\nanchor #{$k}:"; $hrefAttr = $targetAnchor->get_href(); if ($hrefAttr) { echo "\n Full href: " . $hrefAttr; } else { echo "\n Failed to get href"; } } else { echo "\nFailed to get anchor #{$k}"; } } } else { echo "Failed to retrieve anchors with partial href '{$href}'\n"; } // Example 4: Get anchors by href in a specific frame (frame=0) $href = "https://example.com/frame"; $anchors = DOM::$anchor->get_all_by_href($href, false, "0"); // Check if frame exists first $frameExists = DOM::$frame->is_exist_by_number(0); if ($frameExists) { echo "\n\nFrame 0 exists\n"; // Check if the operation was successful if ($anchors) { echo "Successfully retrieved anchors with href '{$href}' in frame 0\n"; // Get count of anchors in frame $count = $anchors->get_count(); echo "\n\nTotal anchors found with href '{$href}' in frame 0: {$count}"; } else { echo "Failed to retrieve anchors with href '{$href}' in frame 0\n"; } } else { echo "\n\nFrame 0 does not exist\n"; } } else { echo "Failed to wait for page to load\n"; } } else { echo "Failed to navigate to anchor.html\n"; } echo("\n"); // Quit the application WINDOW::$app->quit(); ?>
# Additional paths import sys sys.path.insert(0, '../../../Templates PY/') xhe_host = "127.0.0.1:7010" from xweb_human_emulator import * # начало echo("<hr><font color=blue>common.get_all_by_href</font><hr>") # 1 echo("1. Перейдем на полигон : ") echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html"),"<br>") # 2 echo("2. Получить inner text всех ссылок c заданным href : ") print(anchor.get_all_by_href("#").get_inner_text()) # конец echo("<hr><br>") # Quit app.quit()
#region using using System; using System.Diagnostics; using System.Collections.Generic; using System.Linq; using System.IO; using System.Text; using System.Threading; using XHE; using XHE.XHE_DOM; using XHE.XHE_System; using XHE.XHE_Window; using XHE.XHE_Web; #endregion class Program:XHEScript { static void Main(string[] args) { // init XHE server = "localhost:7010"; InitXHE(); // начало echo("<hr><font color=blue>get_all_by_href</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Получить inner text всех ссылкок c заданным href : \n"); echo(anchor.get_all_by_href("#").get_inner_text()); // конец echo("\n\n"); app.quit(); } }
// подключим функциональные объекты, если еще не подключен xhe_host="127.0.0.1:7010"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>anchor.get_all_by_href</font><hr>"); // 1 шаг echo("1. Перейдем на полигон : "); echo(browser.navigate("https://rpa-bot.ru/wiki/poligon/anchor.html")+"<br>"); // 2 шаг echo("2. Получить inner text всех ссылкок c заданным href : \n\n"); echo(anchor.get_all_by_href("#").get_inner_text()); // конец echo("\n"); // Quit app.quit();
=============================================
Общие функции Объекты DOM System Vision Web Window
=============================================
Если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум.
PS: В тестовом примере приведена работа с конкретным объектом DOM, но данная функция есть во всех DOM объектах, т.е она существует у всех объектов из категории DOM.