init(in_file, proxy_file="", proceed_js=true); - инициализировать сборщик url
Функция на вход принимает параметры:
in_file – путь к файлу с url, содержимое которых надо собрать proxy_file – путь к файлу с прокси что используются при сборе proceed_js – обрабатывать ли JS при сборе
После отработки функция возвращает результат своей работы в робот :
true – успешно инициализировали
false – инициализировать не удалось
Пример использования init (PHP):
<?php $xhe_host = "127.0.0.1:7022"; // + cef // подключим объект для управления эмулятором, если еще не подключен if (!isset($path)) $path="../../../Templates/init.php"; require($path); // начало echo "<hr><font color=blue>webpage->".basename (__FILE__)."</font><hr>"; // 1 echo "1. Сфорируем файл с урлами : "; $path="test/in_file.urls"; echo $file_os->delete("test/in_file.urls")." "; echo $textfile->add_string_to_file("test/in_file.urls","ya.ru\n")." "; echo $textfile->add_string_to_file("test/in_file.urls","google.com\n")." "; echo $textfile->add_string_to_file("test/in_file.urls","yandex.ru\n")." "; echo $textfile->add_string_to_file("test/in_file.urls","vk.com\n")." "; echo $textfile->add_string_to_file("test/in_file.urls","ttttttt\n")." "; echo $textfile->add_string_to_file("test/in_file.urls","http://whoer.net\n")." "; // 2 echo "\n2. Инициализируем сборщик файлом с урлами: "; echo $harvestor->init("test/in_file.urls")." "; // 3 echo "\n3. Запуститм сбор и дождемся окончания : "; echo $harvestor->start(false)."<br>"; while (!$harvestor->is_finished()) echo ".".$harvestor->get_completed_count()."."; // 4 echo "\n4. Выведем длину полученных урлов в файле : "; $count = $textfile->get_lines_count($path); for ($i=0;$i<$count;$i++) echo strlen($harvestor->get_html($i))." "; // 5 echo "\n5. Инициализируем сборщик файлом с урлами, используя прокси и без JS: "; echo $harvestor->init("test/in_file.urls","test/proxies.txt",false)." "; // 6 echo "\n6. Запуститм сбор и дождемся окончания : "; echo $harvestor->start(false)."<br>"; while (!$harvestor->is_finished()) { echo ".".$harvestor->get_completed_count()."."; sleep(1); } // 7 echo "\n7. Выведем длину полученных урлов в файле : "; $count = $textfile->get_lines_count($path); for ($i=0;$i<$count;$i++) echo strlen($harvestor->get_html($i))." "; // конец echo "<hr><br>"; // Quit $app->quit(); ?>
Пример использования init (C#):
#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="127.0.0.1:7022"; InitXHE(); // начало echo("<hr><font color=blue>ftp.command</font><hr>"); // 1 echo("1. Сфорируем файл с урлами : "); string path="test\\in_file.urls"; echo(file_os.delete("test/in_file.urls")+" "); echo(textfile.add_string_to_file("test\\in_file.urls","ya.ru\n")+" "); echo(textfile.add_string_to_file("test\\in_file.urls","google.com\n")+" "); echo(textfile.add_string_to_file("test\\in_file.urls","yandex.ru\n")+" "); echo(textfile.add_string_to_file("test\\in_file.urls","vk.com\n")+" "); echo(textfile.add_string_to_file("test\\in_file.urls","ttttttt\n")+" "); // 2 echo("\n2. Инициализируем сборщик файлом с урлами: "); echo(harvestor.init("test\\in_file.urls")+" "); // 3 echo("\n3. Запуститм сбор и дождемся окончания : "); echo(harvestor.start(false)+"<br>"); while (!harvestor.is_finished()) { echo("."+harvestor.get_completed_count()+"."); sleep(1); } // 4 echo("\n4. Выведем длину полученных урлов в файле : "); int count = textfile.get_lines_count(path); for (int i=0;i<count;i++) echo(harvestor.get_html(i).Length+" "); // 5 echo("\n5. Инициализируем сборщик файлом с урлами (используя прокси и без обработки JS): "); echo(harvestor.init("test\\in_file.urls","test\\proxies.txt",false)+" "); // 6 echo("\n6. Запуститм сбор и дождемся окончания : "); echo(harvestor.start(false)+"<br>"); while (!harvestor.is_finished()) { echo("."+harvestor.get_completed_count()+"."); sleep(1); } // 7 echo("\n7. Выведем длину полученных урлов в файле : "); count = textfile.get_lines_count(path); for (int i=0;i<count;i++) echo(harvestor.get_html(i).Length+" "); // конец echo("<hr><br>"); app.quit(); } }
Пример использования init (Python):
# Additional paths import sys sys.path.insert(0, '../../../Templates PY/') xhe_host = "127.0.0.1:7022" from xweb_human_emulator import * # начало echo("<hr><font color=blue>ftp.xxxxxxxxx</font><hr>") # 1 echo("1. Сфорируем файл с урлами : "); path = "test/in_file.urls"; echo(file_os.delete("test/in_file.urls")," "); echo(textfile.add_string_to_file("test/in_file.urls","ya.ru\n")," "); echo(textfile.add_string_to_file("test/in_file.urls","google.com\n")," "); echo(textfile.add_string_to_file("test/in_file.urls","yandex.ru\n")," "); echo(textfile.add_string_to_file("test/in_file.urls","vk.com\n")," "); echo(textfile.add_string_to_file("test/in_file.urls","ttttttt\n")," "); # 2 echo("\n2. Инициализируем сборщик файлом с урлами: "); echo(harvestor.init("test/in_file.urls")," "); # 3 echo("\n3. Запуститм сбор и дождемся окончания : "); echo(harvestor.start(false),"<br>"); while not harvestor.is_finished(): echo("."+str(harvestor.get_completed_count())+"."); sleep(1); # 4 echo("\n4. Выведем длину полученных урлов в файле : "); count = textfile.get_lines_count(path); for i in range(0, count): echo(len(harvestor.get_html(i))," ") # 5 echo("\n5. Инициализируем сборщик файлом с урлами: "); echo(harvestor.init("test/in_file.urls","test/proxies.txt",false)," "); # 6 echo("\n6. Запуститм сбор и дождемся окончания : "); echo(harvestor.start(false),"<br>"); while not harvestor.is_finished(): echo("."+str(harvestor.get_completed_count())+"."); sleep(1); # 7 echo("\n7. Выведем длину полученных урлов в файле : "); count = textfile.get_lines_count(path); for i in range(0, count): echo(len(harvestor.get_html(i))," ") # конец echo("<hr><br>") # Quit app.quit()
Пример использования init (JS):
// подключим объект для управления эмулятором, если еще не подключен xhe_host="127.0.0.1:7022"; echo=require("../../../Templates JS/init.js"); // начало echo("<hr><font color=blue>ftp.command</font><hr>"); // 1 echo("1. Сфорируем файл с урлами : "); path="test/in_file.urls"; echo(file_os.delete("test/in_file.urls")+" "); echo(textfile.add_string_to_file("test/in_file.urls","ya.ru\n")+" "); echo(textfile.add_string_to_file("test/in_file.urls","google.com\n")+" "); echo(textfile.add_string_to_file("test/in_file.urls","yandex.ru\n")+" "); echo(textfile.add_string_to_file("test/in_file.urls","vk.com\n")+" "); echo(textfile.add_string_to_file("test/in_file.urls","ttttttt\n")+" "); // 2 echo("\n2. Инициализируем сборщик файлом с урлами: "); echo(harvestor.init("test/in_file.urls")+" "); // 3 echo("\n3. Запуститм сбор и дождемся окончания : "); echo(harvestor.start(false)+"<br>"); while (!harvestor.is_finished()) echo("."+harvestor.get_completed_count()+"."); // 4 echo("\n4. Выведем длину полученных урлов в файле : "); count = textfile.get_lines_count(path); for (i=0;i<count;i++) echo(harvestor.get_html(i).length," "); // 5 echo("\n5. Инициализируем сборщик файлом с урлами: "); echo(harvestor.init("test/in_file.urls","test/proxies.txt",false)+" "); // 6 echo("\n6. Запуститм сбор и дождемся окончания : "); echo(harvestor.start(false)+"<br>"); while (!harvestor.is_finished()) echo("."+harvestor.get_completed_count()+"."); // 7 echo("\n7. Выведем длину полученных урлов в файле : "); count = textfile.get_lines_count(path); for (i=0;i<count;i++) echo(harvestor.get_html(i).length," "); // конец echo("<hr><br>"); // Quit app.quit();