SampleTest.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. package org.jeecg;
  2. import cn.com.ctop.bytedance.service.IByteDanceHourlyAccountWarningService;
  3. import cn.com.ctop.bytedance.service.IReportService;
  4. import cn.com.ctop.common.module.entity.CtopOauthToken;
  5. import cn.com.ctop.common.module.mapper.CtopOauthTokenMapper;
  6. import cn.com.ctop.common.module.service.ICtopOauthTokenService;
  7. import cn.com.ctop.common.module.utils.CtopAdConstant;
  8. import cn.com.ctop.common.module.utils.HttpUtils2;
  9. import cn.com.ctop.crawler.modules.appium.service.IAppiumJobService;
  10. import cn.com.ctop.crawler.modules.appium.service.IAppiumTaskService;
  11. import cn.com.ctop.kuaishou.modules.batch.service.IAccountWarningService;
  12. import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
  13. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  14. import lombok.extern.slf4j.Slf4j;
  15. import org.apache.http.impl.client.BasicCookieStore;
  16. import org.jeecg.common.util.DateUtils;
  17. import org.jeecg.modules.ctop.service.IBidWarningService;
  18. import org.jeecg.modules.ctop.service.ICreateInternalService;
  19. import org.jeecg.modules.mq.Sender;
  20. import org.junit.Test;
  21. import org.junit.runner.RunWith;
  22. import org.openqa.selenium.By;
  23. import org.openqa.selenium.JavascriptExecutor;
  24. import org.openqa.selenium.WebDriver;
  25. import org.openqa.selenium.WebElement;
  26. import org.openqa.selenium.chrome.ChromeDriver;
  27. import org.openqa.selenium.chrome.ChromeOptions;
  28. import org.springframework.beans.factory.annotation.Autowired;
  29. import org.springframework.beans.factory.annotation.Value;
  30. import org.springframework.boot.test.context.SpringBootTest;
  31. import org.springframework.test.context.junit4.SpringRunner;
  32. import java.text.SimpleDateFormat;
  33. import java.util.Date;
  34. import java.util.List;
  35. import java.util.concurrent.ExecutorService;
  36. import java.util.concurrent.Executors;
  37. @RunWith(SpringRunner.class)
  38. @SpringBootTest
  39. @Slf4j
  40. public class SampleTest {
  41. @Value("${jeecg.path.chrome-driver}")
  42. private String chromeDriver;
  43. @Autowired
  44. private IAppiumJobService jobService;
  45. @Autowired
  46. private ICreateInternalService createInternalService;
  47. @Autowired
  48. private IAppiumTaskService appiumTaskService;
  49. @Test
  50. public void testKs() throws InterruptedException {
  51. String url = "https://ad.e.kuaishou.com/#/welcome?redirectUrl=https%3A%2F%2Fad.e.kuaishou.com%2F%23%2Findex";
  52. System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
  53. ChromeOptions chromeOptions = new ChromeOptions();
  54. // chromeOptions.addArguments("--headless");
  55. chromeOptions.addArguments("--incognito");
  56. chromeOptions.addArguments("--disable-gpu");
  57. // chromeOptions.addArguments("--no-sandbox");
  58. chromeOptions.addArguments("--window-size=1920,1080");
  59. chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
  60. chromeOptions.setAcceptInsecureCerts(true);
  61. WebDriver webDriver = new ChromeDriver(chromeOptions);
  62. try {
  63. Thread.sleep(3000L);
  64. HttpUtils2.cookieStore = new BasicCookieStore();
  65. webDriver.manage().deleteAllCookies();
  66. //获取登录页面
  67. webDriver.get(url);
  68. Thread.sleep(3000L);
  69. WebElement accountElement = webDriver.findElement(By.xpath("//div[@class='phone ']/input[@type='text']"));
  70. accountElement.sendKeys("19845004383");
  71. Thread.sleep(3000L);
  72. WebElement passwordElement = webDriver.findElement(By.xpath("//div[@class='password ']/input[@type='password']"));
  73. passwordElement.sendKeys("a123456");
  74. WebElement loginElement = webDriver.findElement(By.xpath("//div[@class='foot']"));
  75. Thread.sleep(3000L);
  76. //点击登录
  77. loginElement.click();
  78. Thread.sleep(3000L);
  79. //获取推广按钮
  80. WebElement spreadElement = webDriver.findElement(By.linkText("推广"));
  81. spreadElement.click();
  82. Thread.sleep(3000L);
  83. //选择广告创意
  84. WebElement creativeElement = webDriver.findElement(By.xpath("//div[text()='广告创意']"));
  85. creativeElement.click();
  86. Thread.sleep(3000L);
  87. //输入创意名称,点击搜索
  88. WebElement searchElement = webDriver.findElement(By.xpath("//input[@type='text']"));
  89. searchElement.sendKeys("2-这个是你画的吗-设计-11.19");
  90. Thread.sleep(3000L);
  91. WebElement searchButton = webDriver.findElement(By.xpath("//button[@class='ant-btn ant-input-search-button ant-btn-primary']"));
  92. searchButton.click();
  93. Thread.sleep(3000L);
  94. WebElement tiyanElement = webDriver.findElement(By.linkText("体验"));
  95. tiyanElement.click();
  96. Thread.sleep(2000L);
  97. WebElement inputKsIdElement = webDriver.findElement(By.xpath("//textarea[@placeholder='请输入快手账号…']"));
  98. inputKsIdElement.sendKeys("123456765");
  99. Thread.sleep(2000L);
  100. WebElement chufaElement = webDriver.findElement(By.xpath("//button[@class='creative-experience-btn-enable']"));
  101. chufaElement.click();
  102. } catch (Exception e) {
  103. e.printStackTrace();
  104. webDriver.manage().deleteAllCookies();
  105. webDriver.close();
  106. }
  107. }
  108. @Test
  109. public void test() {
  110. jobService.refreshWebPhone();
  111. }
  112. @Test
  113. public void testMq() {
  114. Sender sender = new Sender();
  115. sender.send();
  116. }
  117. @Test
  118. public void loadKuaishouDataSingle() throws Exception {
  119. String url = "https://a201903112120030590198943.szwego.com/static/index.html#/shop_detail/A201903112120030590198943";
  120. System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
  121. ChromeOptions chromeOptions = new ChromeOptions();
  122. // chromeOptions.addArguments("--headless");
  123. chromeOptions.addArguments("--incognito");
  124. chromeOptions.addArguments("--disable-gpu");
  125. // chromeOptions.addArguments("--no-sandbox");
  126. chromeOptions.addArguments("--window-size=1920,1080");
  127. chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
  128. chromeOptions.setAcceptInsecureCerts(true);
  129. WebDriver webDriver = new ChromeDriver(chromeOptions);
  130. webDriver.get(url);
  131. Thread.sleep(3000L);
  132. ((JavascriptExecutor) webDriver).executeScript("window.scrollTo(0,document.body.scrollHeight)");
  133. Thread.sleep(3000L);
  134. List<WebElement> elementList = webDriver.findElements(By.xpath("//div[@class='word-break ellipsis-two f14 g3']"));
  135. for (WebElement element : elementList) {
  136. System.out.println(element.getText());
  137. }
  138. }
  139. @Autowired
  140. private IKuaishouInterfaceService kuaishouInterfaceService;
  141. @Test
  142. public void testMail() throws Exception {
  143. // String accessToken, Long advertiserId, Date startDate, Date endDate, Integer page
  144. kuaishouInterfaceService.getTargetingTags(23212L, "101a5c994d0a87322f305a306a30e38e");
  145. }
  146. @Autowired
  147. private IBidWarningService bidWarningService;
  148. @Autowired
  149. private IAccountWarningService accountWarningService;
  150. @Autowired
  151. private CtopOauthTokenMapper oauthTokenMapper;
  152. static ExecutorService executorService = Executors.newFixedThreadPool(5);
  153. @Test
  154. public void testMa() throws Exception {
  155. // accountWarningService.accountWarning(23212L);
  156. QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
  157. oauthTokenQueryWrapper.eq("media_id", 2);
  158. List<CtopOauthToken> ctopOauthTokens = oauthTokenMapper.selectList(oauthTokenQueryWrapper);
  159. for (CtopOauthToken token : ctopOauthTokens) {
  160. kuaishouInterfaceService.getCreativeList(token, null, null);
  161. }
  162. }
  163. @Autowired
  164. private ICtopOauthTokenService tokenService;
  165. @Autowired
  166. private IReportService reportService;
  167. @Autowired
  168. private IByteDanceHourlyAccountWarningService byteDanceHourlyAccountWarningService;
  169. @Test
  170. public void testMa2() throws Exception {
  171. byteDanceHourlyAccountWarningService.byteDanceAccountWarning(1655337394471943L,"2020-02-06","2020-02-05");
  172. /*Date getDate = new Date();
  173. SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH");
  174. String hour = simpleDateFormat.format(getDate);
  175. if (null != hour && "00".equals(hour)) {
  176. getDate = DateUtils.addDay(getDate, -1);
  177. }
  178. //1:查询当日数据
  179. List<CtopOauthToken> tokens = tokenService.getTokenListByType(CtopAdConstant.PLATFORM_TYPE_BYTEDANCE);
  180. if (null == tokens || tokens.size() <= 0) {
  181. log.info("定时获取头条小时数据异常:未获取到可用的token");
  182. return;
  183. }
  184. Date finalGetDate = getDate;
  185. QueryWrapper<CtopOauthToken> oauthTokenQueryWrapper = new QueryWrapper<>();
  186. oauthTokenQueryWrapper.eq("account_id", 1655337394471943L);
  187. CtopOauthToken ctopOauthToken = oauthTokenMapper.selectOne(oauthTokenQueryWrapper);*/
  188. //1: 获取广告主信息数据
  189. // reportService.getAdvertiserReport(ctopOauthToken, finalGetDate, finalGetDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  190. //2:获取广告组信息数据
  191. //reportService.getAdvertiserCampaignReport(token, finalGetDate, finalGetDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  192. //3:获取广告计划信息数据
  193. //reportService.getAdvertiserPlanReport(token, finalGetDate, finalGetDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  194. //4: 获取广告创意信息数据
  195. //reportService.getAdvertiserCreativeReport(token, finalGetDate, finalGetDate, CtopAdConstant.BYTEDANCE_REPORT_TYPE_HOURLY);
  196. }
  197. }