|
@@ -1,6 +1,6 @@
|
|
package cn.com.ctop.toutiao.test;
|
|
package cn.com.ctop.toutiao.test;
|
|
|
|
|
|
-import cn.com.ctop.common.utils.HttpUtils;
|
|
|
|
|
|
+import cn.com.ctop.common.utils.HttpUtils2;
|
|
import cn.com.ctop.crawler.modules.core.util.FateadmHttpUtil;
|
|
import cn.com.ctop.crawler.modules.core.util.FateadmHttpUtil;
|
|
import cn.com.ctop.crawler.modules.core.util.FateadmUtil;
|
|
import cn.com.ctop.crawler.modules.core.util.FateadmUtil;
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
@@ -22,21 +22,23 @@ import java.util.Map;
|
|
|
|
|
|
public class Test {
|
|
public class Test {
|
|
|
|
|
|
- @Value("${jeecg.path.chrome-driver}")
|
|
|
|
- private String chromeDriver;
|
|
|
|
|
|
+// @Value("${jeecg.path.chrome-driver}")
|
|
|
|
+// private String chromeDriver;
|
|
|
|
|
|
- public void test(String url) {
|
|
|
|
- System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
|
|
|
|
|
|
+ public static void main(String args[]) {
|
|
|
|
+ String url = "https://ad.oceanengine.com/pages/login/index.html";
|
|
|
|
+ System.getProperties().setProperty("webdriver.chrome.driver", "D:/chromedriver.exe");
|
|
try {
|
|
try {
|
|
ChromeOptions chromeOptions = new ChromeOptions();
|
|
ChromeOptions chromeOptions = new ChromeOptions();
|
|
- WebDriver webDriver = new ChromeDriver(chromeOptions);
|
|
|
|
- chromeOptions.addArguments("--headless");
|
|
|
|
- chromeOptions.addArguments("--incognito");
|
|
|
|
|
|
+// chromeOptions.addArguments("--headless");
|
|
|
|
+// chromeOptions.addArguments("--incognito");
|
|
chromeOptions.addArguments("--no-sandbox");
|
|
chromeOptions.addArguments("--no-sandbox");
|
|
- chromeOptions.addArguments("--disable-gpu");
|
|
|
|
- chromeOptions.addArguments("--window-size=1290,1080");
|
|
|
|
- chromeOptions.addArguments("--user-agent="+HttpUtils.USER_AGENT);
|
|
|
|
|
|
+// chromeOptions.addArguments("--disable-gpu");
|
|
|
|
+ chromeOptions.addArguments("--window-size=1920,1080");
|
|
|
|
+ chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
|
|
chromeOptions.setAcceptInsecureCerts(true);
|
|
chromeOptions.setAcceptInsecureCerts(true);
|
|
|
|
+ WebDriver webDriver = new ChromeDriver(chromeOptions);
|
|
|
|
+
|
|
webDriver.get(url); //获取登录页面
|
|
webDriver.get(url); //获取登录页面
|
|
|
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
@@ -51,7 +53,7 @@ public class Test {
|
|
|
|
|
|
ck.setExpiryDate(cookie.getExpiry());
|
|
ck.setExpiryDate(cookie.getExpiry());
|
|
ck.setPath(cookie.getPath());
|
|
ck.setPath(cookie.getPath());
|
|
- HttpUtils.cookieStore.addCookie(ck);
|
|
|
|
|
|
+ HttpUtils2.cookieStore.addCookie(ck);
|
|
System.out.println(cookie.getName()+","+cookie.getValue()+","+cookie.getDomain());
|
|
System.out.println(cookie.getName()+","+cookie.getValue()+","+cookie.getDomain());
|
|
// ck.setDomain(".sso.toutiao.com");
|
|
// ck.setDomain(".sso.toutiao.com");
|
|
// HttpUtils.cookieStore.addCookie(ck);
|
|
// HttpUtils.cookieStore.addCookie(ck);
|
|
@@ -73,9 +75,10 @@ public class Test {
|
|
param.put("account","dcd_ad@bytedance.com");
|
|
param.put("account","dcd_ad@bytedance.com");
|
|
param.put("password","typdDCD@2018");
|
|
param.put("password","typdDCD@2018");
|
|
param.put("captcha","hqde");
|
|
param.put("captcha","hqde");
|
|
|
|
+ param.put("captcha_key", "DlhagAeAIcAAAAAAAAARAAA");
|
|
param.put("is_30_days_no_login","true");
|
|
param.put("is_30_days_no_login","true");
|
|
param.put("service","https://ad.oceanengine.com");
|
|
param.put("service","https://ad.oceanengine.com");
|
|
- String res = HttpUtils.httpPostParamRequest("https://sso.toutiao.com/account_login/",param,header);
|
|
|
|
|
|
+ String res = HttpUtils2.httpPostParamRequest("https://sso.toutiao.com/account_login/", param, header);
|
|
// System.out.println(res);
|
|
// System.out.println(res);
|
|
// Scanner scanner = new Scanner(System.in);
|
|
// Scanner scanner = new Scanner(System.in);
|
|
// String code = scanner.nextLine();
|
|
// String code = scanner.nextLine();
|
|
@@ -94,11 +97,13 @@ public class Test {
|
|
fateadmUtil.Justice(orderId);
|
|
fateadmUtil.Justice(orderId);
|
|
}
|
|
}
|
|
String captcha = jsonNode.get("captcha").asText();
|
|
String captcha = jsonNode.get("captcha").asText();
|
|
|
|
+ String captchaKey = jsonNode.get("captcha_key").asText();
|
|
BASE64Decoder decoder =new BASE64Decoder();
|
|
BASE64Decoder decoder =new BASE64Decoder();
|
|
FateadmHttpUtil.HttpResp resp = fateadmUtil.Predict("30400",decoder.decodeBuffer(captcha));
|
|
FateadmHttpUtil.HttpResp resp = fateadmUtil.Predict("30400",decoder.decodeBuffer(captcha));
|
|
param.put("captcha",resp.pred_resl);
|
|
param.put("captcha",resp.pred_resl);
|
|
|
|
+ param.put("captcha_key", captchaKey);
|
|
orderId = resp.req_id;
|
|
orderId = resp.req_id;
|
|
- res = HttpUtils.httpPostParamRequest("https://sso.toutiao.com/account_login/",param,header);
|
|
|
|
|
|
+ res = HttpUtils2.httpPostParamRequest("https://sso.toutiao.com/account_login/", param, header);
|
|
System.out.println(res);
|
|
System.out.println(res);
|
|
jsonNode = mapper.readTree(res);
|
|
jsonNode = mapper.readTree(res);
|
|
errorCode = jsonNode.get("error_code").asInt();
|
|
errorCode = jsonNode.get("error_code").asInt();
|
|
@@ -107,7 +112,7 @@ public class Test {
|
|
// String redirectUrl = jsonNode.get("redirect_url").asText();
|
|
// String redirectUrl = jsonNode.get("redirect_url").asText();
|
|
// webDriver.get(redirectUrl);
|
|
// webDriver.get(redirectUrl);
|
|
String csrftoken = "";
|
|
String csrftoken = "";
|
|
- List<org.apache.http.cookie.Cookie> cookies = HttpUtils.cookieStore.getCookies();
|
|
|
|
|
|
+ List<org.apache.http.cookie.Cookie> cookies = HttpUtils2.cookieStore.getCookies();
|
|
for(org.apache.http.cookie.Cookie ck : cookies){
|
|
for(org.apache.http.cookie.Cookie ck : cookies){
|
|
Cookie cookie = new Cookie(ck.getName(),ck.getValue(),"."+ck.getDomain(),ck.getPath(),ck.getExpiryDate());
|
|
Cookie cookie = new Cookie(ck.getName(),ck.getValue(),"."+ck.getDomain(),ck.getPath(),ck.getExpiryDate());
|
|
webDriver.manage().addCookie(cookie);
|
|
webDriver.manage().addCookie(cookie);
|
|
@@ -143,7 +148,7 @@ public class Test {
|
|
ck.setDomain("ad.oceanengine.com");
|
|
ck.setDomain("ad.oceanengine.com");
|
|
ck.setExpiryDate(cookie.getExpiry());
|
|
ck.setExpiryDate(cookie.getExpiry());
|
|
ck.setPath(cookie.getPath());
|
|
ck.setPath(cookie.getPath());
|
|
- HttpUtils.cookieStore.addCookie(ck);
|
|
|
|
|
|
+ HttpUtils2.cookieStore.addCookie(ck);
|
|
System.out.println(cookie.getName()+","+cookie.getValue()+","+cookie.getDomain());
|
|
System.out.println(cookie.getName()+","+cookie.getValue()+","+cookie.getDomain());
|
|
}
|
|
}
|
|
header.put("Accept","application/json, text/javascript, */*; q=0.01");
|
|
header.put("Accept","application/json, text/javascript, */*; q=0.01");
|
|
@@ -154,7 +159,7 @@ public class Test {
|
|
header.put("X-CSRFToken",csrftoken);
|
|
header.put("X-CSRFToken",csrftoken);
|
|
header.put("X-Requested-With","XMLHttpRequest");
|
|
header.put("X-Requested-With","XMLHttpRequest");
|
|
header.put("Referer","https://ad.oceanengine.com/pages/campaign/create.html");
|
|
header.put("Referer","https://ad.oceanengine.com/pages/campaign/create.html");
|
|
- res = HttpUtils.httpPostRequest("https://ad.oceanengine.com/overture/campaign/create/",param2,header);// 创建广告组返回信息
|
|
|
|
|
|
+ res = HttpUtils2.httpPostRequest("https://ad.oceanengine.com/overture/campaign/create/", param2, header);// 创建广告组返回信息
|
|
System.out.println(res);
|
|
System.out.println(res);
|
|
JsonNode node = mapper.readTree(res);
|
|
JsonNode node = mapper.readTree(res);
|
|
//{"status": "fail", "msg": "\u5e7f\u544a\u7ec4\u4e0d\u80fd\u91cd\u590d", "type": "form_error", "name": "campaign_name"}
|
|
//{"status": "fail", "msg": "\u5e7f\u544a\u7ec4\u4e0d\u80fd\u91cd\u590d", "type": "form_error", "name": "campaign_name"}
|
|
@@ -168,18 +173,18 @@ public class Test {
|
|
ck.setDomain("ad.oceanengine.com");
|
|
ck.setDomain("ad.oceanengine.com");
|
|
ck.setExpiryDate(cookie.getExpiry());
|
|
ck.setExpiryDate(cookie.getExpiry());
|
|
ck.setPath(cookie.getPath());
|
|
ck.setPath(cookie.getPath());
|
|
- HttpUtils.cookieStore.addCookie(ck);
|
|
|
|
|
|
+ HttpUtils2.cookieStore.addCookie(ck);
|
|
System.out.println(cookie.getName()+","+cookie.getValue()+","+cookie.getDomain());
|
|
System.out.println(cookie.getName()+","+cookie.getValue()+","+cookie.getDomain());
|
|
}
|
|
}
|
|
- String siteStr = HttpUtils.httpGetRequest("https://ad.oceanengine.com/overture/api/adv_site/get_site_list/?_=" + String.valueOf(System.currentTimeMillis()));
|
|
|
|
- String convStr = HttpUtils.httpGetRequest("https://ad.oceanengine.com/overture/api/get_tetris_action/?external_url=&type=external&pricing=9&landing_type=3&_=" + String.valueOf(System.currentTimeMillis()));
|
|
|
|
|
|
+ String siteStr = HttpUtils2.httpGetRequest("https://ad.oceanengine.com/overture/api/adv_site/get_site_list/?_=" + String.valueOf(System.currentTimeMillis()));
|
|
|
|
+ String convStr = HttpUtils2.httpGetRequest("https://ad.oceanengine.com/overture/api/get_tetris_action/?external_url=&type=external&pricing=9&landing_type=3&_=" + String.valueOf(System.currentTimeMillis()));
|
|
JsonNode siteNode = mapper.readTree(siteStr);
|
|
JsonNode siteNode = mapper.readTree(siteStr);
|
|
JsonNode convNode = mapper.readTree(convStr);
|
|
JsonNode convNode = mapper.readTree(convStr);
|
|
|
|
|
|
Map<String,Object> param4 = new HashMap<String,Object>();
|
|
Map<String,Object> param4 = new HashMap<String,Object>();
|
|
param4.put("location_type",4);
|
|
param4.put("location_type",4);
|
|
param4.put("aweme_account_fans",0);
|
|
param4.put("aweme_account_fans",0);
|
|
- String tokenStr = HttpUtils.httpPostRequest("https://ad.oceanengine.com/api/v1/hl/ad/audience/estimate/",param4,header);
|
|
|
|
|
|
+ String tokenStr = HttpUtils2.httpPostRequest("https://ad.oceanengine.com/api/v1/hl/ad/audience/estimate/", param4, header);
|
|
System.out.println(siteStr);
|
|
System.out.println(siteStr);
|
|
System.out.println(convStr);
|
|
System.out.println(convStr);
|
|
System.out.println(tokenStr);
|
|
System.out.println(tokenStr);
|
|
@@ -222,7 +227,7 @@ public class Test {
|
|
param5.put("app_bid_ratio",new Object());
|
|
param5.put("app_bid_ratio",new Object());
|
|
param5.put("name","自动创建测试4"); //广计划名称
|
|
param5.put("name","自动创建测试4"); //广计划名称
|
|
param5.put("campaign_id",campaignId);
|
|
param5.put("campaign_id",campaignId);
|
|
- String createResult = HttpUtils.httpPostRequest("https://ad.oceanengine.com/overture/ad/create/",param5,header);
|
|
|
|
|
|
+ String createResult = HttpUtils2.httpPostRequest("https://ad.oceanengine.com/overture/ad/create/", param5, header);
|
|
System.out.println(createResult);
|
|
System.out.println(createResult);
|
|
}
|
|
}
|
|
// webDriver.close();
|
|
// webDriver.close();
|