|
@@ -21,10 +21,11 @@ import org.apache.commons.io.FileUtils;
|
|
import org.apache.http.impl.client.BasicCookieStore;
|
|
import org.apache.http.impl.client.BasicCookieStore;
|
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
|
import org.apache.http.impl.cookie.BasicClientCookie;
|
|
import org.jeecg.common.util.DateUtils;
|
|
import org.jeecg.common.util.DateUtils;
|
|
-import org.openqa.selenium.*;
|
|
|
|
import org.openqa.selenium.NoSuchElementException;
|
|
import org.openqa.selenium.NoSuchElementException;
|
|
|
|
+import org.openqa.selenium.*;
|
|
import org.openqa.selenium.chrome.ChromeDriver;
|
|
import org.openqa.selenium.chrome.ChromeDriver;
|
|
import org.openqa.selenium.chrome.ChromeOptions;
|
|
import org.openqa.selenium.chrome.ChromeOptions;
|
|
|
|
+import org.openqa.selenium.interactions.Actions;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -54,19 +55,32 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
|
|
private KuaishouAgentAccountMapper kuaishouAgentAccountMapper;
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
@Value("${jeecg.path.chrome-driver}")
|
|
private String chromeDriver;
|
|
private String chromeDriver;
|
|
|
|
+ @Value("${jeecg.path.kuaishou-agent-image}")
|
|
|
|
+ private String kuaishouAgentImage;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void replaceBatch(List<KuaishouReportDailyAgent> list) {
|
|
public void replaceBatch(List<KuaishouReportDailyAgent> list) {
|
|
kuaishouReportDailyAgentMapper.replaceBatch(list);
|
|
kuaishouReportDailyAgentMapper.replaceBatch(list);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void tapPoint(WebDriver driver, Integer x, Integer y) {
|
|
|
|
+ WebElement element = driver.findElement(By.tagName("iframe"));
|
|
|
|
+ Actions actions = new Actions(driver);
|
|
|
|
+ actions.moveToElement(element,x,y).click().perform();
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(500L);
|
|
|
|
+ } catch (InterruptedException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
public boolean loginAgent() {
|
|
public boolean loginAgent() {
|
|
boolean loginStatus = false;
|
|
boolean loginStatus = false;
|
|
System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
|
|
System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
|
|
String url = "https://agent.e.kuaishou.com";
|
|
String url = "https://agent.e.kuaishou.com";
|
|
ChromeOptions chromeOptions = new ChromeOptions();
|
|
ChromeOptions chromeOptions = new ChromeOptions();
|
|
-// chromeOptions.addArguments("--headless");
|
|
|
|
-// chromeOptions.addArguments("--no-sandbox");
|
|
|
|
|
|
+ chromeOptions.addArguments("--headless");
|
|
|
|
+ chromeOptions.addArguments("--no-sandbox");
|
|
chromeOptions.addArguments("--disable-dev-shm-usage");
|
|
chromeOptions.addArguments("--disable-dev-shm-usage");
|
|
chromeOptions.addArguments("--incognito");
|
|
chromeOptions.addArguments("--incognito");
|
|
chromeOptions.addArguments("--disable-gpu");
|
|
chromeOptions.addArguments("--disable-gpu");
|
|
@@ -95,15 +109,21 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
log.error("【错误】快手登录出现验证码!");
|
|
log.error("【错误】快手登录出现验证码!");
|
|
File scrFile = captureElement(webDriver.findElement(By.tagName("iframe")));
|
|
File scrFile = captureElement(webDriver.findElement(By.tagName("iframe")));
|
|
//clickCharBg
|
|
//clickCharBg
|
|
- String savePath = "D:/temp.png";
|
|
|
|
- FileUtils.copyFile(scrFile, new File(savePath));
|
|
|
|
- webDriver.switchTo().frame(webDriver.findElement(By.tagName("iframe")));
|
|
|
|
- String result = ChaojiyingUtils.process(Base64Utils.imageToBase64(savePath),9104);
|
|
|
|
- System.out.println(result);
|
|
|
|
|
|
+ FileUtils.copyFile(scrFile, new File(kuaishouAgentImage));
|
|
|
|
+ String result = ChaojiyingUtils.process(Base64Utils.imageToBase64(kuaishouAgentImage),9104);
|
|
String pointString = JSONObject.parseObject(result).getString("pic_str");
|
|
String pointString = JSONObject.parseObject(result).getString("pic_str");
|
|
-
|
|
|
|
- ((JavascriptExecutor) webDriver).executeScript("arguments[0].click();", webDriver.findElement(By.className("aq_icon_refresh")));
|
|
|
|
|
|
+ String[] split = pointString.split("\\|");
|
|
|
|
+ if(split.length>0){
|
|
|
|
+ for(int i=0;i<split.length;i++){
|
|
|
|
+ String pointStr = split[i];
|
|
|
|
+ String [] taps = pointStr.split(",");
|
|
|
|
+ tapPoint(webDriver,Integer.parseInt(taps[0]),Integer.parseInt(taps[1]));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ webDriver.switchTo().frame(webDriver.findElement(By.tagName("iframe")));
|
|
|
|
+ webDriver.findElement(By.xpath("//div[@class='opArea']/span[@id='submit']")).click();
|
|
}
|
|
}
|
|
|
|
+ Thread.sleep(3000L);
|
|
webDriver.get("https://agent.e.kuaishou.com/#/index");
|
|
webDriver.get("https://agent.e.kuaishou.com/#/index");
|
|
Thread.sleep(3000L);
|
|
Thread.sleep(3000L);
|
|
Set<Cookie> cookies = webDriver.manage().getCookies();
|
|
Set<Cookie> cookies = webDriver.manage().getCookies();
|
|
@@ -144,18 +164,15 @@ public class KuaishouReportDailyAgentServiceImpl extends ServiceImpl<KuaishouRep
|
|
}
|
|
}
|
|
|
|
|
|
public File captureElement(WebElement element) throws Exception {
|
|
public File captureElement(WebElement element) throws Exception {
|
|
- // TODO Auto-generated method stub
|
|
|
|
WrapsDriver wrapsDriver = (WrapsDriver) element;
|
|
WrapsDriver wrapsDriver = (WrapsDriver) element;
|
|
// 截图整个页面
|
|
// 截图整个页面
|
|
File screen = ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.FILE);
|
|
File screen = ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.FILE);
|
|
-// ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.)
|
|
|
|
- String tempPath = "D:/temp.png";
|
|
|
|
- FileUtils.copyFile(screen, new File(tempPath));
|
|
|
|
- BufferedImage img = ImageIO.read(new File(tempPath));
|
|
|
|
|
|
+ FileUtils.copyFile(screen, new File(kuaishouAgentImage));
|
|
|
|
+ BufferedImage img = ImageIO.read(new File(kuaishouAgentImage));
|
|
// 获得元素的高度和宽度
|
|
// 获得元素的高度和宽度
|
|
int width = element.getSize().getWidth();
|
|
int width = element.getSize().getWidth();
|
|
int height = element.getSize().getHeight();
|
|
int height = element.getSize().getHeight();
|
|
-// // 得到元素的坐标
|
|
|
|
|
|
+ // 得到元素的坐标
|
|
Point p = element.getLocation();
|
|
Point p = element.getLocation();
|
|
BufferedImage dest = img.getSubimage(p.x, p.y, width, height);
|
|
BufferedImage dest = img.getSubimage(p.x, p.y, width, height);
|
|
// 存为png格式
|
|
// 存为png格式
|