chrome動(dòng)態(tài)ip python
import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.Platform;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.gargoylesoftware.htmlunit.DefaultCredentialsProvider;
import com.gargoylesoftware.htmlunit.WebClient;
public class FirefoxDriverProxyDemo
{
// 代理隧道驗(yàn)證信息
final static String proxyUser = "H01234567890123D";
final static String proxyPass = "0123456789012345";
// 代理服務(wù)器
final static String proxyHost = "http-dyn.abuyun.com";
final static int proxyPort = 9020;
final static String firefoxBin = "D:/Program Files/Mozilla Firefox/firefox.exe";
public static void main(String[] args) throws JSONException
{
System.setProperty("webdriver.firefox.bin", firefoxBin);
FirefoxProfile profile = new FirefoxProfile();
// 使用代理
profile.setPreference("network.proxy.type", 1);
// 代理服務(wù)器配置
profile.setPreference("network.proxy.http", proxyHost);
profile.setPreference("network.proxy.http_port", proxyPort);
profile.setPreference("network.proxy.ssl", proxyHost);
profile.setPreference("network.proxy.ssl_port", proxyPort);
profile.setPreference("username", proxyUser);
profile.setPreference("password", proxyPass);
// 所有協(xié)議公用一種代理配置,如果單獨(dú)配置,這項(xiàng)設(shè)置為false
profile.setPreference("network.proxy.share_proxy_settings", true);
// 對(duì)于localhost的不用代理,這里必須要配置,否則無法和webdriver通訊
profile.setPreference("network.proxy.no_proxies_on", "localhost");
// 以代理方式啟動(dòng)firefox
FirefoxDriver driver = new FirefoxDriver(profile);
}
}