浏览代码

Merge branch 'master' of https://gitee.com/hcst/adsp-boot

syh 5 年之前
父节点
当前提交
fea64f361c

+ 3 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/IKuaishouWebInterfaceService.java

@@ -1,12 +1,13 @@
 package cn.com.ctop.kuaishou.modules.graphql.service;
 package cn.com.ctop.kuaishou.modules.graphql.service;
 
 
+import java.io.IOException;
 import java.util.Map;
 import java.util.Map;
 
 
 public interface IKuaishouWebInterfaceService {
 public interface IKuaishouWebInterfaceService {
-    public void getVideoList(String uid);
+    public void getVideoList(String uid) throws IOException;
     public String checkKuaishouUser(String videoUrl);
     public String checkKuaishouUser(String videoUrl);
 
 
-    public void adkuaishouWebLogin(String phone, String password);
+    public void adkuaishouWebLogin(String phone, String password) throws IOException;
 
 
     public void deleteAllComment(Map<String, String> pcursorMap);
     public void deleteAllComment(Map<String, String> pcursorMap);
 }
 }

+ 11 - 2
module-kuaishou/src/main/java/cn/com/ctop/kuaishou/modules/graphql/service/impl/KuaishouWebInterfaceServiceImpl.java

@@ -17,6 +17,7 @@ import org.openqa.selenium.By;
 import org.openqa.selenium.Cookie;
 import org.openqa.selenium.Cookie;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.WebDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.chrome.ChromeDriver;
+import org.openqa.selenium.chrome.ChromeDriverService;
 import org.openqa.selenium.chrome.ChromeOptions;
 import org.openqa.selenium.chrome.ChromeOptions;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.support.ui.WebDriverWait;
 import org.openqa.selenium.support.ui.WebDriverWait;
@@ -24,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 
 
+import java.io.File;
+import java.io.IOException;
 import java.io.UnsupportedEncodingException;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
 import java.net.URLEncoder;
 import java.text.SimpleDateFormat;
 import java.text.SimpleDateFormat;
@@ -191,7 +194,9 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
     private String chromeDriver;
     private String chromeDriver;
 
 
     @Override
     @Override
-    public void adkuaishouWebLogin(String phone, String password) {
+    public void adkuaishouWebLogin(String phone, String password) throws IOException {
+        ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File(chromeDriver)).usingAnyFreePort().build();
+        service.start();
         System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         ChromeOptions chromeOptions = new ChromeOptions();
         ChromeOptions chromeOptions = new ChromeOptions();
         WebDriver webDriver = new ChromeDriver(chromeOptions);
         WebDriver webDriver = new ChromeDriver(chromeOptions);
@@ -243,12 +248,15 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
             e.printStackTrace();
             e.printStackTrace();
         } finally {
         } finally {
             webDriver.quit();
             webDriver.quit();
+            service.stop();
 //            HttpUtils.cookieStore.clear();
 //            HttpUtils.cookieStore.clear();
         }
         }
     }
     }
 
 
     @Override
     @Override
-    public void getVideoList(String uid) {
+    public void getVideoList(String uid) throws IOException {
+        ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File(chromeDriver)).usingAnyFreePort().build();
+        service.start();
         System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         ChromeOptions chromeOptions = new ChromeOptions();
         ChromeOptions chromeOptions = new ChromeOptions();
         WebDriver webDriver = new ChromeDriver(chromeOptions);
         WebDriver webDriver = new ChromeDriver(chromeOptions);
@@ -290,6 +298,7 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         } finally {
         } finally {
 //            HttpUtils.cookieStore.clear();
 //            HttpUtils.cookieStore.clear();
             webDriver.quit();
             webDriver.quit();
+            service.stop();
         }
         }
     }
     }