我正在使用 Selenium 编写一个需要多线程的网络爬虫
// selenium imports from org.openqa omitted
public class wpn
{
private String sessionId = "";
private String windowHandle = "";
private WebDriver driver;
public wpn (String id)
{
sessionId = id;
}
public void openDriver (String driverType)
{
if (driverType.equals ("ie"))
{
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
capabilities.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
capabilities.setCapability("requireWindowFocus", true);
System.setProperty("webdriver.ie.driver", "c:\\temp\\ieDriver.exe");
driver = new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();
}
else if (driverType.equals ("chrome"))
{
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
System.setProperty("webdriver.chrome.driver", "c:\\temp\\chromedriver.exe");
driver = new ChromeDriver (capabilities);
driver.manage().window().maximize();
}
else if (driverType.equals ("phantom"))
{
File file = new File("c:\\temp\\phantomJSDdriver.exe");
System.setProperty("phantomjs.binary.path", file.getAbsolutePath ());
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes"});
driver = new PhantomJSDriver(capabilities);
Dimension dimension = new Dimension (1280, 1024);
driver.manage().window().setSize (dimension);
}
噜噜哒
相关分类