|
@@ -0,0 +1,111 @@
|
|
|
|
+package cn.com.ctop.toutiao.modules.report.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.com.ctop.common.module.utils.ChaojiyingUtils;
|
|
|
|
+import cn.com.ctop.common.module.utils.HttpUtils2;
|
|
|
|
+import cn.com.ctop.toutiao.modules.report.service.IBytedanceReportDailyAgentService;
|
|
|
|
+import org.apache.http.impl.client.BasicCookieStore;
|
|
|
|
+import org.apache.http.impl.cookie.BasicClientCookie;
|
|
|
|
+import org.openqa.selenium.By;
|
|
|
|
+import org.openqa.selenium.Cookie;
|
|
|
|
+import org.openqa.selenium.WebDriver;
|
|
|
|
+import org.openqa.selenium.WebElement;
|
|
|
|
+import org.openqa.selenium.chrome.ChromeDriver;
|
|
|
|
+import org.openqa.selenium.chrome.ChromeOptions;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Iterator;
|
|
|
|
+import java.util.Map;
|
|
|
|
+import java.util.Set;
|
|
|
|
+
|
|
|
|
+public class BytedanceReportDailyAgentServiceImpl implements IBytedanceReportDailyAgentService {
|
|
|
|
+// @Value("${jeecg.path.chrome-driver}")
|
|
|
|
+ private String chromeDriver = "D:/chromedriver.exe";
|
|
|
|
+ public static void main(String[] args){
|
|
|
|
+ BytedanceReportDailyAgentServiceImpl i = new BytedanceReportDailyAgentServiceImpl();
|
|
|
|
+ //账户列表 get
|
|
|
|
+ //https://agent.oceanengine.com/agent/optimize/adv-manage/adv-list/history/?beginDate=2020-07-03&endDate=2020-07-03&page=1&size=10&sortDir=descend&sortField=salesCost
|
|
|
|
+ //公司列表 post
|
|
|
|
+ //https://agent.oceanengine.com/agent/optimize/adv-company-manage/company-list/history/
|
|
|
|
+ /**
|
|
|
|
+ * Content-Disposition: form-data; name="page"
|
|
|
|
+ * 1
|
|
|
|
+ * Content-Disposition: form-data; name="size"
|
|
|
|
+ * 10
|
|
|
|
+ * Content-Disposition: form-data; name="sortField"
|
|
|
|
+ * advertiserCompanyCost
|
|
|
|
+ * Content-Disposition: form-data; name="sortDir"
|
|
|
|
+ * descend
|
|
|
|
+ * Content-Disposition: form-data; name="beginDate"
|
|
|
|
+ * 2020-07-01
|
|
|
|
+ */
|
|
|
|
+ i.loginAgent();
|
|
|
|
+ }
|
|
|
|
+ public boolean loginAgent() {
|
|
|
|
+ boolean loginStatus = false;
|
|
|
|
+ System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
|
|
|
|
+ String url = "https://agent.oceanengine.com/login";
|
|
|
|
+ ChromeOptions chromeOptions = new ChromeOptions();
|
|
|
|
+ chromeOptions.addArguments("--headless");
|
|
|
|
+ chromeOptions.addArguments("--no-sandbox");
|
|
|
|
+ chromeOptions.addArguments("--disable-dev-shm-usage");
|
|
|
|
+ chromeOptions.addArguments("--incognito");
|
|
|
|
+ chromeOptions.addArguments("--disable-gpu");
|
|
|
|
+ chromeOptions.addArguments("--window-size=1920,1080");
|
|
|
|
+ chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
|
|
|
|
+ chromeOptions.setAcceptInsecureCerts(true);
|
|
|
|
+ WebDriver webDriver = new ChromeDriver(chromeOptions);
|
|
|
|
+ try {
|
|
|
|
+ Thread.sleep(3000L);
|
|
|
|
+ HttpUtils2.cookieStore = new BasicCookieStore();
|
|
|
|
+ webDriver.manage().deleteAllCookies();
|
|
|
|
+ //获取登录页面
|
|
|
|
+ webDriver.get(url);
|
|
|
|
+ Thread.sleep(3000L);
|
|
|
|
+ WebElement accountElement = webDriver.findElement(By.xpath("//input[@name='account']"));
|
|
|
|
+ accountElement.sendKeys("guoyanling@c-top.com.cn");
|
|
|
|
+ Thread.sleep(3000L);
|
|
|
|
+ WebElement passwordElement = webDriver.findElement(By.xpath("//input[@name='password']"));
|
|
|
|
+ passwordElement.sendKeys("HCST-hcst888");
|
|
|
|
+ WebElement captchaElement = webDriver.findElement(By.xpath("//div[contains(@class,'custom-toutiao-captcha')]"));
|
|
|
|
+ String bg = captchaElement.getCssValue("background-image");
|
|
|
|
+ System.out.println(bg.split("\"")[1]);
|
|
|
|
+ String result = ChaojiyingUtils.process(bg.split(",")[1],1004);
|
|
|
|
+ //{"err_no":0,"err_str":"OK","pic_id":"9109919322855101177","pic_str":"jdww","md5":"230db313e423211fcd989a9b4797fd87"}
|
|
|
|
+ WebElement captchaInputElement = webDriver.findElement(By.xpath("//input[@name='captcha']"));
|
|
|
|
+ System.out.println(result);
|
|
|
|
+ WebElement loginElement = webDriver.findElement(By.xpath("//div[contains(text(),'登录')]"));
|
|
|
|
+ Thread.sleep(3000L);
|
|
|
|
+ //点击登录
|
|
|
|
+ loginElement.click();
|
|
|
|
+ Thread.sleep(3000L);
|
|
|
|
+
|
|
|
|
+ Set<Cookie> cookies = webDriver.manage().getCookies();
|
|
|
|
+ Iterator iterator = cookies.iterator();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ String cookieStr = iterator.next().toString();
|
|
|
|
+ String[] cookieArray = cookieStr.split(";");
|
|
|
|
+ Map<String, String> cookieMap = new HashMap<>();
|
|
|
|
+ for (String cookie : cookieArray) {
|
|
|
|
+ String[] kv = cookie.split("=");
|
|
|
|
+ if (kv.length > 1) {
|
|
|
|
+ cookieMap.put(kv[0].trim(), kv[1].trim());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ BasicClientCookie clientCookie = new BasicClientCookie(cookieArray[0].split("=")[0],
|
|
|
|
+ cookieArray[0].split("=")[1]);
|
|
|
|
+ clientCookie.setDomain("agent.oceanengine.com");
|
|
|
|
+ clientCookie.setPath(cookieMap.get("path"));
|
|
|
|
+ HttpUtils2.cookieStore.addCookie(clientCookie);
|
|
|
|
+ }
|
|
|
|
+ loginStatus = true;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ loginStatus = false;
|
|
|
|
+ } finally {
|
|
|
|
+ webDriver.manage().deleteAllCookies();
|
|
|
|
+ webDriver.quit();
|
|
|
|
+ }
|
|
|
|
+ return loginStatus;
|
|
|
|
+ }
|
|
|
|
+}
|