Commit c67dea4e9d96b8ab07044a6aea345fc5d007afa5

Authored by 王明元
1 parent f07408ba

2023年6月2日15:47:39 快手/抖音, 登录判断账号是否解锁数据授权

db/freya.mv.db
No preview for this file type
src/main/java/cn/fw/freya/service/crawl/impl/DouYinCrawl.java
... ... @@ -118,13 +118,19 @@ public class DouYinCrawl implements CrawlStrategy {
118 118 }
119 119 if (!Objects.equals(driver.getCurrentUrl(), "https://creator.douyin.com/") && Objects.nonNull(element)) {
120 120 if (accountNo.equals(element.getText())) {
121   - List<WebElement> elements = new WebDriverWait(driver, 2, 300).until(driver1 ->
  121 + List<WebElement> elements = new WebDriverWait(driver, 3, 300).until(driver1 ->
122 122 driver1.findElements(By.xpath("//span[text()='立即解锁']")));
  123 + Integer type = this.getType().getValue();
123 124 if (!elements.isEmpty()) {
  125 + try {
  126 + common.reportAccountNotUnlock(accountNo, type);
  127 + } catch (Exception exception) {
  128 + log.error("上报账号未解锁出现异常");
  129 + this.exitBrowser(accountNo, null);
  130 + }
124 131 this.exitBrowser(accountNo, null);
125 132 throw new BusinessException("请联系抖音账号为: " + accountNo + " 的员工登录'抖音创作服务平台'解锁");
126 133 } else {
127   - Integer type = this.getType().getValue();
128 134 common.saveCookie(driver, accountNo, type);// 保存该用户的cookies
129 135 accountService.updateAccountCookiesStatus(accountNo, type, true);
130 136 accountService.whenLoginCheckAccountExist(accountNo, type);
... ...
src/main/java/cn/fw/freya/service/crawl/impl/KuaiShouCrawl.java
... ... @@ -194,7 +194,6 @@ public class KuaiShouCrawl implements CrawlStrategy, SmartLifecycle {
194 194 Integer type = this.getType().getValue();
195 195 driver.get("https://cp.kuaishou.com/statistics/works");// 跳转到'视频数据'页面
196 196 WebElement lockFlag;// 未解锁标志
197   - boolean canAccess = true;// 有数据权限
198 197 try {
199 198 WebElement webElement = new WebDriverWait(driver, 5, 300).until(driver1 ->
200 199 driver1.findElement(By.xpath("//div[text()='核心数据趋势']")));// '核心数据趋势'元素
... ... @@ -208,13 +207,12 @@ public class KuaiShouCrawl implements CrawlStrategy, SmartLifecycle {
208 207 log.error("上报账号未解锁出现异常");
209 208 this.exitBrowser(accountNo, null);
210 209 }
211   - canAccess = false;
  210 + this.exitBrowser(accountNo, null);
  211 + throw new BusinessException("请联系快手账号为: " + accountNo + " 的员工登录'快手创作服务平台'解锁");
212 212 }
213 213 }
214   - if (canAccess) {
215   - accountService.updateAccountCookiesStatus(accountNo, type, true);
216   - accountService.whenLoginCheckAccountExist(accountNo, type);// 登录时候检查该账号是否已经存在本地
217   - }
  214 + accountService.updateAccountCookiesStatus(accountNo, type, true);
  215 + accountService.whenLoginCheckAccountExist(accountNo, type);// 登录时候检查该账号是否已经存在本地
218 216 common.saveCookie(driver, accountNo, type);// 保存该用户的cookies
219 217 this.exitBrowser(accountNo, null);
220 218 return true;
... ...