PhantomJs+Google image search
来源:互联网 发布:植物图片合成软件下载 编辑:程序博客网 时间:2024/06/06 02:25
@Test
public void testPhantomjs() throws GoogleValidationException{
String proxy = "station3:808";
String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
org.openqa.selenium.Proxy p = new org.openqa.selenium.Proxy();
p.setHttpProxy(proxy).setFtpProxy(proxy).setSslProxy(proxy);
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(CapabilityType.PROXY, p);
capability.setJavascriptEnabled(true);
capability.setCapability("phantomjs.page.settings.userAgent",userAgent);
capability.setPlatform(Platform.WINDOWS);
capability.setVersion("40.1");
((DesiredCapabilities) capability).setJavascriptEnabled(true);
((DesiredCapabilities) capability).setCapability("takesScreenshot", true);
((DesiredCapabilities) capability).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"src/main/resources/phantomjs/phantomjs.exe"
);
PhantomJSDriver driver = new PhantomJSDriver(capability);
driver.get("https://www.google.com/imghp?hl=en&tab=wi");
driver.findElement(By.xpath(".//span[contains(@id,'qbi')]")).click();
driver.findElement(By.xpath(".//a[contains(@class,'qbtbha qbtbtxt qbclr')]")).click();
log.info(driver.getTitle());
driver.executePhantomJS("var page = this; page.uploadFile('input[id=qbfile]', 'D:/MediaUploadRoot/20150827/th.jpg');");
log.info(driver.getTitle());
(new WebDriverWait(driver, 60)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//img[contains(@class,'_u6')]")));
log.info(driver.getTitle());
List<WebElement> webElements = driver.findElements(By.xpath(".//a[contains(@class,'_gUb')]"));
for (WebElement webElement : webElements) {
String googleTag = GoogleTranslateUtils.translateToEnglish(webElement.getText());
List<String> tagList = NLPUtil.getTagsForSentence(googleTag);
log.info("NLPUtil---------------------->tagList: "+tagList);
}
}
public void testPhantomjs() throws GoogleValidationException{
String proxy = "station3:808";
String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
org.openqa.selenium.Proxy p = new org.openqa.selenium.Proxy();
p.setHttpProxy(proxy).setFtpProxy(proxy).setSslProxy(proxy);
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(CapabilityType.PROXY, p);
capability.setJavascriptEnabled(true);
capability.setCapability("phantomjs.page.settings.userAgent",userAgent);
capability.setPlatform(Platform.WINDOWS);
capability.setVersion("40.1");
((DesiredCapabilities) capability).setJavascriptEnabled(true);
((DesiredCapabilities) capability).setCapability("takesScreenshot", true);
((DesiredCapabilities) capability).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"src/main/resources/phantomjs/phantomjs.exe"
);
PhantomJSDriver driver = new PhantomJSDriver(capability);
driver.get("https://www.google.com/imghp?hl=en&tab=wi");
driver.findElement(By.xpath(".//span[contains(@id,'qbi')]")).click();
driver.findElement(By.xpath(".//a[contains(@class,'qbtbha qbtbtxt qbclr')]")).click();
log.info(driver.getTitle());
driver.executePhantomJS("var page = this; page.uploadFile('input[id=qbfile]', 'D:/MediaUploadRoot/20150827/th.jpg');");
log.info(driver.getTitle());
(new WebDriverWait(driver, 60)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//img[contains(@class,'_u6')]")));
log.info(driver.getTitle());
List<WebElement> webElements = driver.findElements(By.xpath(".//a[contains(@class,'_gUb')]"));
for (WebElement webElement : webElements) {
String googleTag = GoogleTranslateUtils.translateToEnglish(webElement.getText());
List<String> tagList = NLPUtil.getTagsForSentence(googleTag);
log.info("NLPUtil---------------------->tagList: "+tagList);
}
}
0 0
- PhantomJs+Google image search
- An API for Google Image Search
- Search Google
- google search
- deeplearning image search test
- phantomjs
- phantomjs
- phantomjs
- PhantomJS
- PhantomJS
- phantomjs
- phantomjs
- PhantomJS
- phantomjs
- google weather Image
- Google Desktop Search
- google's map search
- other use google search
- DCT变换
- 算法导论习题2.1-4
- nand flash ecc level
- java js实现Websocket通讯实例
- 解决eclipse卡死问题
- PhantomJs+Google image search
- Clustergram: visualization and diagnostics for cluster analysis (R code)
- java中this关键字的应用
- login shell的配置初始化
- 有关程序后台和前台运行监听
- c++虚函数,虚继承 详解
- swift-工具方法
- Android String类详解
- Asimplecache框架的使用