Browser automation allows you to perform tasks automatically in the Lalicat browser profiles, supports the local API interface function, reads and writes the account configuration information, starts and closes the browser, queries the account list, and configures the proxy IP, etc. through a programmatic way.
Lalicat API Instruction: Lalicat API File
Part 2 Based on Selenium WebDriver, Lalicat can support Puppeteer
Usually, if you run selenium code, first connect to the chrome driver, and then set the functions you need. You don't need to do this when you use Lalicat with selenium code. You will use the web driver program to connect to Lalicat application or a browser profile through the local port, set the required functions, and execute the selenium command in the predefined browser configuration file.
Of course, you can also leave Selenium and Puppeteer automation framework and directly call our API to perform automation operations.
How to connect Puppeteer with Lalicat browser?
Part 3 Supported Language
It can run on multiple coding languages. There are examples for Python and Java at the bottom of this tutorial.
Part 4 Use in Lalicat
1. Define Lalicat Port
You need to define software ports in advance to use automation. The following is how to define ports:
Setting -> Browser -> Monitoring and Port
2. Check the API Token.
3. Lalicat Browser Kernel Version:
If it is 96, please download:
http://chromedriver.storage.googleapis.com/96.0.4664.45/chromedriver_win32.zip
If it is 98, please download:
http://chromedriver.storage.googleapis.com/98.0.4758.80/chromedriver_win32.zip
If chromedriver Version is not catched right, will cause automation failed.
If you cannot close the browser, you can use the interface of http://127.0.0.1:30725/api/v1/profile/stop?profileId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx to close the browser process of the specified configuration.
If you can only open the browser (but can not open the website) when running the code, you need to copy [chromedriver.exe] to your Python Installation Directory. Or, if you have chosen mobile emulation mode, please change it.
4. The interface can also pass in the proxy server information. If the proxy information is passed in, it will overwrite the proxy information in the configuration file. This coverage is temporary and will not really modify the configuration file. It is only valid for automated interfaces: Markup
http://127.0.0.1:30725/api/v1/profile/start?automation=true&profileId=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&proxytype=socks5&proxyserver=ip&proxyport=1080&proxyusername=&proxypassword=
C++
There are 4 types of proxy:
proxytype=socks5
proxytype=socks4
proxytype=http
proxytype=https
The proxy username and password can be blank.
Part 5. Python Use Cases:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import requests
mla_profile_id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'
mla_url = 'http://127.0.0.1:30725/api/v1/profile/start?automation=true&profileId='+mla_profile_id
resp = requests.get(mla_url)
json = resp.json()
print(json['value'])
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", json['value'][7:])
chrome_driver = r"chromedriver.exe"
#http://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_win32.zip
#Download chromedriver file and put into the category of Python
driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options)
driver.get('https://www.lalimao.com/')
executor_url = driver.command_executor._url
session_id = driver.session_id
print(executor_url)
print(session_id)
print('ok it is done')
driver.quit()
Part 6. JAVA Use Case
package com.ruoyi.common.spider.reptile;
import cn.hutool.json.JSONObject;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
/**
* @author lalicat
* <dependency>
* <groupId>org.seleniumhq.selenium</groupId>
* <artifactId>selenium-java</artifactId>
* <version>3.141.59</version>
* </dependency>
*/
public class ProductChrome {
public static void main(String[] args) throws Exception {
ProductChrome pc = new ProductChrome();
String profileId = UUID.randomUUID().toString();
//Based on profileId to open and get remote address
URL url = new URL(pc.startProfile("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"));
//Use remote address to link to opened chrome browser
System.setProperty("webdriver.chrome.driver", "D:\\lalimao\\chrome\\90.0.4430.85\\chromedriver.exe");//Point to Driver position
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("debuggerAddress", url.getAuthority());
WebDriver driver = new ChromeDriver(chromeOptions);
//Visit lalicat
driver.get("https://www.lalicat.com/");
System.out.println(driver.getTitle());
driver.quit();
}
private String startProfile(String profileId) throws Exception {
String url = "http://127.0.0.1:30725/api/v1/profile/start?automation=true&profileId=" + profileId;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
JSONObject jsonResponse = new JSONObject(response.toString());
return jsonResponse.getStr("value");
}
}
We Offer 3-Day Free Trial for All New Users
No Limitations in Features