Kibor Bot Autoclicker » Kibor - Integrated development environment for bots » Textbook Kibor » Browser automation with Kibor Python and Selenium

Страниц (1): [1]
 

1. Kibor - 09 Августа, 2020 - 07:22:40 - перейти к сообщению
Explaining Browser Automation with Kibor, Python, and Selenium
Using Python in Kibor.
Browser automation with Selenium.
Demonstration of the search in Google for the desired site for the necessary queries and the transition to it.

Working with the browser is linked to page elements. Doesn't depend on appearance, window resolution and so on. Works in the background. Maybe without the browser itself.







CODE:

string find="Распознать текст OCR";//Request
string path_webdriver=pathfolder()+"python\webdriver\geckodriver.exe"; // Way to webdriver. C:\Program Files (x86)\Kibor\python\webdriver\geckodriver.exe
string path_browser="C:\Program Files (x86)\Mozilla Firefox\Firefox.exe"; // Путь к браузеру Мозила

if (runpython()==0){messagebox ("Failed to start Python"); goto er;}//Run the interpreter Python

//Training
import();

//Launching the browser and switching to https://www.google.com
start_browser();

//We find on the Google search page a field for entering the search and enter the query there
find_google();

//Search on the page of the opened search for a link that leads to kibor-bot.com and click on it
F: if (find_site("kibor-bot.com")==0)//If this page does not link to kibor-bot.com
{// You need to go to the next search page
if (find_site("Next") == 0) goto exits; //If there is no Next button on this page, exit the program - MUST BE NAME OF BUTTON NEXT IN SEARCH GUGLA
pause (5000); //If you clicked the Next pause button for 5 seconds and repeat the search for a link to kibor-bot.com
goto F;
}



exits:;
closepython();//Finishing work with the interpreter
er:;

function find_site(string find_link)//Search on the page of the opened search for a link that leads to the specified link
{
string rez;
sendpython("web.find_element_by_partial_link_text(^'"+find_link+"^').click()");//We send Python a command to find the link containing kibor-bot.com and click on it
sendpython("print(^'yes^')");//Immediately without waiting for the end of the first Send command print('yes')

loop()//A closed loop in which we are waiting for an answer
{
rez=getpython();//Trying to read the answer If the link was not found, then in addition to yes, the answer will contain a description of the error.
if (rez!="ERROR_READ_PYTHON") // If Python answered us something ..
{
//messagebox (rez+);//See what comes when they found a link and when they did not find it
if (rez=="yes")return 1;//If the answer only contains the word yes, then we found a link and there is no description of the error.
return 0;//Otherwise, the answer is not only the word yes. So we didnt find the link
}
}
}

function find_google()//We find on the Google search page a field for entering the search and enter the value of the find variable there
{
// First, we initialize the variable finds in Pythen with our variable find with a synchronous function
sendgetpython("finds=^'"+find+"^'"); // finds=find
__python
element = web.find_element_by_name('q')
element.send_keys(finds)
time.sleep(1);
element.send_keys(Keys.ENTER)
time.sleep(3);
print('yes')
__end_python
while (getpython()!="yes")sleep(100);// We are waiting for the answer "yes" in the loop. It will be when the Python script runs
}

function start_browser()//Launching the browser
{
//First, we initialize the variables in Pythen with our synchronous functions.
sendgetpython("p_web=^'"+path_webdriver+"^'");// p_web=path_webdriver
sendgetpython("p_br=^'"+path_browser+"^'"); // p_br=path_browser
__python
web = webdriver.Firefox(executable_path=p_web, firefox_binary=p_br) # Тут мы используе переменные p_web и p_br
web.get('https://www.google.com')
time.sleep(1);
print('yes')
__end_python
while (getpython()!="yes")sleep(100);// We are waiting for the answer "yes" in the loop. It will be when the Python script runs
}


function import()//Training
{
__python
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print('yes')
__end_python
while (getpython()!="yes")sleep(100);// We are waiting for the answer "yes" in the loop. It will be when the Python script runs
}

Powered by ExBB FM 1.0 Final