|
@@ -1,7 +1,9 @@
|
|
|
package cn.com.ctop.kuaishou.modules.graphql.service.impl;
|
|
|
|
|
|
+import cn.com.ctop.common.module.entity.BindAccountLogin;
|
|
|
import cn.com.ctop.common.module.entity.HttpClientEntity;
|
|
|
import cn.com.ctop.common.module.entity.IpPool;
|
|
|
+import cn.com.ctop.common.module.service.IBindAccountLoginService;
|
|
|
import cn.com.ctop.common.module.service.IIpPoolService;
|
|
|
import cn.com.ctop.common.module.utils.HttpClientUtils;
|
|
|
import cn.com.ctop.common.module.utils.HttpUtils2;
|
|
@@ -10,8 +12,6 @@ import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouUserCookie;
|
|
|
import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouWebData;
|
|
|
import cn.com.ctop.kuaishou.modules.graphql.entity.KuaishouWebResult;
|
|
|
import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouUserCookieService;
|
|
|
-import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouUserService;
|
|
|
-import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouVideoService;
|
|
|
import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouWebInterfaceService;
|
|
|
import cn.com.ctop.kuaishou.modules.graphql.vo.KuaishouAcceptVO;
|
|
|
import cn.com.ctop.kuaishou.modules.graphql.vo.KuaishouQrStartVO;
|
|
@@ -74,14 +74,12 @@ import java.util.regex.Pattern;
|
|
|
@Service
|
|
|
public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceService {
|
|
|
@Autowired
|
|
|
- private IKuaishouUserService kuaishouUserService;
|
|
|
- @Autowired
|
|
|
- private IKuaishouVideoService kuaishouVideoService;
|
|
|
- @Autowired
|
|
|
private IKuaishouUserCookieService kuaishouUserCookieService;
|
|
|
@Autowired
|
|
|
private IIpPoolService iIpPoolService;
|
|
|
@Autowired
|
|
|
+ private IBindAccountLoginService bindAccountLoginService;
|
|
|
+ @Autowired
|
|
|
private RedisUtil redisUtil;
|
|
|
public static String GRAPHQL_URL = "https://live.kuaishou.com/graphql";
|
|
|
|
|
@@ -653,6 +651,55 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void getkuaishouWebLoginCookie(BindAccountLogin login){
|
|
|
+ ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File(chromeDriver)).usingAnyFreePort().build();
|
|
|
+ try {
|
|
|
+ service.start();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ ChromeOptions chromeOptions = new ChromeOptions();
|
|
|
+ chromeOptions.addArguments("--headless");
|
|
|
+ chromeOptions.addArguments("--no-sandbox");
|
|
|
+ chromeOptions.addArguments("--disable-dev-shm-usage");
|
|
|
+ chromeOptions.addArguments("--disable-gpu");
|
|
|
+ chromeOptions.addArguments("--window-size=1920,1080");
|
|
|
+ chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
|
|
|
+ chromeOptions.setAcceptInsecureCerts(true);
|
|
|
+ WebDriver webDriver = new RemoteWebDriver(service.getUrl(), chromeOptions);
|
|
|
+ try {
|
|
|
+ //全局隐式等待
|
|
|
+ webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
|
|
+ //设定网址
|
|
|
+ webDriver.get("https://b.e.kuaishou.com");
|
|
|
+ //显示等待控制对象
|
|
|
+ WebDriverWait webDriverWait = new WebDriverWait(webDriver, 10);
|
|
|
+ webDriverWait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".phone input"))).sendKeys(login.getAccountName());
|
|
|
+ webDriverWait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".password input"))).sendKeys(login.getPassword());
|
|
|
+ //点击登录
|
|
|
+ webDriver.findElement(By.className("foot")).click();
|
|
|
+ //等待2秒用于页面加载,保证Cookie响应全部获取。
|
|
|
+ Thread.sleep(10000);
|
|
|
+ webDriver.get("https://b.e.kuaishou.com/#/home/profile");
|
|
|
+ //获取Cookie并打印
|
|
|
+ Set<org.openqa.selenium.Cookie> cookies = webDriver.manage().getCookies();
|
|
|
+ List<String> cookieList = new ArrayList<>();
|
|
|
+ Iterator iterator = cookies.iterator();
|
|
|
+ while (iterator.hasNext()) {
|
|
|
+ String cookieStr = iterator.next().toString();
|
|
|
+ cookieList.add(cookieStr);
|
|
|
+ }
|
|
|
+
|
|
|
+ login.setCookie(new Gson().toJson(cookieList));
|
|
|
+ bindAccountLoginService.updateById(login);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ webDriver.quit();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
|
|
|
System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
|