Pārlūkot izejas kodu

Merge remote-tracking branch 'origin/master'

yumeng 5 gadi atpakaļ
vecāks
revīzija
c5bf7657ac

+ 20 - 0
module-common/src/main/java/cn/com/ctop/common/utils/AliyunOCRUtils.java

@@ -0,0 +1,20 @@
+package cn.com.ctop.common.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class AliyunOCRUtils {
+    private static String host = "https://ocrapi-ecommerce.taobao.com";
+    private static String path = "/ocrservice/ecommerce";
+    private static String appcode = "a62d65f9056f491aa04e2093f85df663";
+
+    public static String getOCRResult(String imageBase64) {
+        Map<String, String> header = new HashMap<String, String>();
+        header.put("Authorization", "APPCODE " + appcode);
+        header.put("Content-Type", "application/json; charset=UTF-8");
+        Map<String, Object> body = new HashMap<String, Object>();
+        body.put("img", "data:image/jpeg;base64," + imageBase64);
+        body.put("prob", false);
+        return HttpUtils.httpPostRequest(host + path, body, header);
+    }
+}

+ 23 - 0
module-common/src/main/java/cn/com/ctop/common/utils/Base64Utils.java

@@ -3,11 +3,16 @@ package cn.com.ctop.common.utils;
 import com.google.gson.Gson;
 import org.apache.commons.net.util.Base64;
 import sun.misc.BASE64Decoder;
+import sun.misc.BASE64Encoder;
 
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
@@ -71,4 +76,22 @@ public class Base64Utils {
 
         return null;
     }
+
+    public static String ImageToBase64(String imgPath) {
+        byte[] data = null;
+        // 读取图片字节数组
+        try {
+            InputStream in = new FileInputStream(imgPath);
+            data = new byte[in.available()];
+            in.read(data);
+            in.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        // 对字节数组Base64编码
+        BASE64Encoder encoder = new BASE64Encoder();
+        // 返回Base64编码过的字节数组字符串
+        return encoder.encode(data);
+//        System.out.println("本地图片转换Base64:" + encoder.encode(Objects.requireNonNull(data)));
+    }
 }

+ 29 - 0
module-common/src/main/java/cn/com/ctop/common/utils/ChaojiyingUtils.java

@@ -0,0 +1,29 @@
+package cn.com.ctop.common.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ChaojiyingUtils {
+    private static String host = "http://upload.chaojiying.net";
+    private static String path = "/Upload/Processing.php";
+    private static String username = "xuzuoyun";
+    private static String password = "heaven";
+    private static Integer softId = 901055;
+
+    public static String process(String imageBase64) {
+        Map<String, Object> params = new HashMap<String, Object>();
+        params.put("user", username);
+        params.put("pass", password);
+        params.put("softid", softId);
+        params.put("codetype", 9005);
+        params.put("file_base64", imageBase64);
+        Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Content-Type", "application/json");
+        return HttpUtils.httpPostRequest(host + path, params, headers);
+    }
+
+    public static String sendError() {
+
+        return null;
+    }
+}

+ 429 - 0
module-common/src/main/java/cn/com/ctop/common/utils/ImageUtils.java

@@ -0,0 +1,429 @@
+package cn.com.ctop.common.utils;
+
+import java.awt.Color;
+import java.awt.Graphics2D;
+import java.awt.Image;
+import java.awt.Rectangle;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Date;
+import java.util.Iterator;
+
+import javax.imageio.ImageIO;
+import javax.imageio.ImageReadParam;
+import javax.imageio.ImageReader;
+import javax.imageio.stream.ImageInputStream;
+
+import com.sun.image.codec.jpeg.ImageFormatException;
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGEncodeParam;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
+
+/**
+ * 图片压缩工具类 提供的方法中可以设定生成的 缩略图片的大小尺寸、压缩尺寸的比例、图片的质量等
+ * <pre>
+ * 	调用示例:
+ * resiz(srcImg, tarDir + "car_1_maxLength_11-220px-hui.jpg", 220, 0.7F);
+ * </pre>
+ *
+ * @author cevencheng
+ * @project haohui-b2b
+ * @create 2012-3-22 下午8:29:01
+ */
+public class ImageUtils {
+
+    /**
+     * * 图片文件读取
+     *
+     * @param srcImgPath
+     * @return
+     */
+    private static BufferedImage InputImage(String srcImgPath) throws RuntimeException {
+
+        BufferedImage srcImage = null;
+        FileInputStream in = null;
+        try {
+            // 构造BufferedImage对象
+            File file = new File(srcImgPath);
+            in = new FileInputStream(file);
+            byte[] b = new byte[5];
+            in.read(b);
+            srcImage = javax.imageio.ImageIO.read(file);
+        } catch (IOException e) {
+            e.printStackTrace();
+            throw new RuntimeException("读取图片文件出错!", e);
+        } finally {
+            if (in != null) {
+                try {
+                    in.close();
+                } catch (IOException e) {
+                    throw new RuntimeException("读取图片文件出错!", e);
+                }
+            }
+        }
+        return srcImage;
+    }
+
+    /**
+     * * 将图片按照指定的图片尺寸、源图片质量压缩(默认质量为1)
+     *
+     * @param srcImgPath :源图片路径
+     * @param outImgPath :输出的压缩图片的路径
+     * @param new_w      :压缩后的图片宽
+     * @param new_h      :压缩后的图片高
+     */
+    public static void resize(String srcImgPath, String outImgPath,
+                              int new_w, int new_h) {
+        resize(srcImgPath, outImgPath, new_w, new_h, 1F);
+    }
+
+    /**
+     * 将图片按照指定的尺寸比例、源图片质量压缩(默认质量为1)
+     *
+     * @param srcImgPath :源图片路径
+     * @param outImgPath :输出的压缩图片的路径
+     * @param ratio      :压缩后的图片尺寸比例
+     *                   :百分比
+     */
+    public static void resize(String srcImgPath, String outImgPath,
+                              float ratio) {
+        resize(srcImgPath, outImgPath, ratio, 1F);
+    }
+
+    /**
+     * 将图片按照指定长或者宽的最大值来压缩图片(默认质量为1)
+     *
+     * @param srcImgPath :源图片路径
+     * @param outImgPath :输出的压缩图片的路径
+     * @param maxLength  :长或者宽的最大值
+     *                   :图片质量
+     */
+    public static void resize(String srcImgPath, String outImgPath,
+                              int maxLength) {
+        resize(srcImgPath, outImgPath, maxLength, 1F);
+    }
+
+    /**
+     * * 将图片按照指定的图片尺寸、图片质量压缩
+     *
+     * @param srcImgPath :源图片路径
+     * @param outImgPath :输出的压缩图片的路径
+     * @param new_w      :压缩后的图片宽
+     * @param new_h      :压缩后的图片高
+     * @param per        :百分比
+     * @author cevencheng
+     */
+    public static void resize(String srcImgPath, String outImgPath,
+                              int new_w, int new_h, float per) {
+        // 得到图片
+        BufferedImage src = InputImage(srcImgPath);
+        int old_w = src.getWidth();
+        // 得到源图宽
+        int old_h = src.getHeight();
+        // 得到源图长
+        // 根据原图的大小生成空白画布
+        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+                BufferedImage.TYPE_INT_RGB);
+        // 在新的画布上生成原图的缩略图
+        Graphics2D g = tempImg.createGraphics();
+        g.setColor(Color.white);
+        g.fillRect(0, 0, old_w, old_h);
+        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+        g.dispose();
+        BufferedImage newImg = new BufferedImage(new_w, new_h,
+                BufferedImage.TYPE_INT_RGB);
+        newImg.getGraphics().drawImage(
+                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+                0, null);
+        // 调用方法输出图片文件
+        outImage(outImgPath, newImg, per);
+    }
+
+    public static BufferedImage resize(BufferedImage src,
+                                       int new_w, int new_h) {
+        int old_w = src.getWidth();
+        // 得到源图宽
+        int old_h = src.getHeight();
+        // 得到源图长
+        // 根据原图的大小生成空白画布
+        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+                BufferedImage.TYPE_INT_RGB);
+        // 在新的画布上生成原图的缩略图
+        Graphics2D g = tempImg.createGraphics();
+        g.setColor(Color.white);
+        g.fillRect(0, 0, old_w, old_h);
+        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+        g.dispose();
+        BufferedImage newImg = new BufferedImage(new_w, new_h,
+                BufferedImage.TYPE_INT_RGB);
+        newImg.getGraphics().drawImage(
+                tempImg, 0,
+                0, null);
+        // 调用方法输出图片文件
+        return newImg;
+    }
+
+    /**
+     * * 将图片按照指定的尺寸比例、图片质量压缩
+     *
+     * @param srcImgPath :源图片路径
+     * @param outImgPath :输出的压缩图片的路径
+     * @param ratio      :压缩后的图片尺寸比例
+     * @param per        :百分比
+     * @author cevencheng
+     */
+    public static void resize(String srcImgPath, String outImgPath,
+                              float ratio, float per) {
+        // 得到图片
+        BufferedImage src = InputImage(srcImgPath);
+        int old_w = src.getWidth();
+        // 得到源图宽
+        int old_h = src.getHeight();
+        // 得到源图长
+        int new_w = 0;
+        // 新图的宽
+        int new_h = 0;
+        // 新图的长
+        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+                BufferedImage.TYPE_INT_RGB);
+        Graphics2D g = tempImg.createGraphics();
+        g.setColor(Color.white);
+        // 从原图上取颜色绘制新图g.fillRect(0, 0, old_w, old_h);
+        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+        g.dispose();
+        // 根据图片尺寸压缩比得到新图的尺寸new_w = (int) Math.round(old_w * ratio);
+        new_h = (int) Math.round(old_h * ratio);
+        BufferedImage newImg = new BufferedImage(new_w, new_h,
+                BufferedImage.TYPE_INT_RGB);
+        newImg.getGraphics().drawImage(
+                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+                0, null);
+        // 调用方法输出图片文件OutImage(outImgPath, newImg, per);
+    }
+
+    /**
+     * <b>
+     * 指定长或者宽的最大值来压缩图片
+     * 推荐使用此方法
+     * </b>
+     *
+     * @param srcImgPath :源图片路径
+     * @param outImgPath :输出的压缩图片的路径
+     * @param maxLength  :长或者宽的最大值
+     * @param per        :图片质量
+     * @author cevencheng
+     */
+    public static void resize(String srcImgPath, String outImgPath,
+                              int maxLength, float per) {
+        // 得到图片
+        BufferedImage src = InputImage(srcImgPath);
+        int old_w = src.getWidth();
+        // 得到源图宽
+        int old_h = src.getHeight();
+        // 得到源图长
+        int new_w = 0;
+        // 新图的宽
+        int new_h = 0;
+        // 新图的长
+        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+                BufferedImage.TYPE_INT_RGB);
+        Graphics2D g = tempImg.createGraphics();
+        g.setColor(Color.white);
+        // 从原图上取颜色绘制新图
+        g.fillRect(0, 0, old_w, old_h);
+        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+        g.dispose();
+        // 根据图片尺寸压缩比得到新图的尺寸
+        if (old_w > old_h) {
+            // 图片要缩放的比例
+            new_w = maxLength;
+            new_h = (int) Math.round(old_h * ((float) maxLength / old_w));
+        } else {
+            new_w = (int) Math.round(old_w * ((float) maxLength / old_h));
+            new_h = maxLength;
+        }
+        BufferedImage newImg = new BufferedImage(new_w, new_h,
+                BufferedImage.TYPE_INT_RGB);
+        newImg.getGraphics().drawImage(
+                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+                0, null);
+        // 调用方法输出图片文件
+        outImage(outImgPath, newImg, per);
+    }
+
+    /**
+     * 将图片压缩成指定宽度, 高度等比例缩放
+     *
+     * @param srcImgPath
+     * @param outImgPath
+     * @param width
+     * @param per
+     */
+    public static void resizeFixedWidth(String srcImgPath, String outImgPath,
+                                        int width, float per) {
+        // 得到图片
+        BufferedImage src = InputImage(srcImgPath);
+        int old_w = src.getWidth();
+        // 得到源图宽
+        int old_h = src.getHeight();
+        // 得到源图长
+        int new_w = 0;
+        // 新图的宽
+        int new_h = 0;
+        // 新图的长
+        BufferedImage tempImg = new BufferedImage(old_w, old_h,
+                BufferedImage.TYPE_INT_RGB);
+        Graphics2D g = tempImg.createGraphics();
+        g.setColor(Color.white);
+        // 从原图上取颜色绘制新图
+        g.fillRect(0, 0, old_w, old_h);
+        g.drawImage(src, 0, 0, old_w, old_h, Color.white, null);
+        g.dispose();
+        // 根据图片尺寸压缩比得到新图的尺寸
+        if (old_w > old_h) {
+            // 图片要缩放的比例
+            new_w = width;
+            new_h = (int) Math.round(old_h * ((float) width / old_w));
+        } else {
+            new_w = (int) Math.round(old_w * ((float) width / old_h));
+            new_h = width;
+        }
+        BufferedImage newImg = new BufferedImage(new_w, new_h,
+                BufferedImage.TYPE_INT_RGB);
+        newImg.getGraphics().drawImage(
+                tempImg.getScaledInstance(new_w, new_h, Image.SCALE_SMOOTH), 0,
+                0, null);
+        // 调用方法输出图片文件
+        outImage(outImgPath, newImg, per);
+    }
+
+    /**
+     * * 将图片文件输出到指定的路径,并可设定压缩质量
+     *
+     * @param outImgPath
+     * @param newImg
+     * @param per
+     * @author cevencheng
+     */
+    private static void outImage(String outImgPath, BufferedImage newImg, float per) {
+        // 判断输出的文件夹路径是否存在,不存在则创建
+        File file = new File(outImgPath);
+        if (!file.getParentFile().exists()) {
+            file.getParentFile().mkdirs();
+        }
+        // 输出到文件流
+        FileOutputStream fos = null;
+        try {
+            fos = new FileOutputStream(outImgPath);
+            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fos);
+            JPEGEncodeParam jep = JPEGCodec.getDefaultJPEGEncodeParam(newImg);
+            // 压缩质量
+            jep.setQuality(per, true);
+            encoder.encode(newImg, jep);
+            fos.close();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (fos != null) {
+                try {
+                    fos.close();
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
+            }
+        }
+    }
+
+    /**
+     * 图片剪切工具方法
+     *
+     * @param srcfile 源图片
+     * @param outfile 剪切之后的图片
+     * @param x       剪切顶点 X 坐标
+     * @param y       剪切顶点 Y 坐标
+     * @param width   剪切区域宽度
+     * @param height  剪切区域高度
+     * @throws IOException
+     * @author cevencheng
+     */
+    public static void cut(File srcfile, File outfile, int x, int y, int width, int height) throws IOException {
+        FileInputStream is = null;
+        ImageInputStream iis = null;
+        try {
+            // 读取图片文件
+            is = new FileInputStream(srcfile);
+
+            /*
+             * 返回包含所有当前已注册 ImageReader 的 Iterator,这些 ImageReader 声称能够解码指定格式。
+             * 参数:formatName - 包含非正式格式名称 .(例如 "jpeg" 或 "tiff")等 。
+             */
+            Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName("jpg");
+            ImageReader reader = it.next();
+            // 获取图片流
+            iis = ImageIO.createImageInputStream(is);
+
+            /*
+             * <p>iis:读取源.true:只向前搜索 </p>.将它标记为 ‘只向前搜索’。
+             * 此设置意味着包含在输入源中的图像将只按顺序读取,可能允许 reader 避免缓存包含与以前已经读取的图像关联的数据的那些输入部分。
+             */
+            reader.setInput(iis, true);
+
+            /*
+             * <p>描述如何对流进行解码的类<p>.用于指定如何在输入时从 Java Image I/O
+             * 框架的上下文中的流转换一幅图像或一组图像。用于特定图像格式的插件 将从其 ImageReader 实现的
+             * getDefaultReadParam 方法中返回 ImageReadParam 的实例。
+             */
+            ImageReadParam param = reader.getDefaultReadParam();
+
+            /*
+             * 图片裁剪区域。Rectangle 指定了坐标空间中的一个区域,通过 Rectangle 对象
+             * 的左上顶点的坐标(x,y)、宽度和高度可以定义这个区域。
+             */
+            Rectangle rect = new Rectangle(x, y, width, height);
+
+            // 提供一个 BufferedImage,将其用作解码像素数据的目标。
+            param.setSourceRegion(rect);
+
+            /*
+             * 使用所提供的 ImageReadParam 读取通过索引 imageIndex 指定的对象,并将 它作为一个完整的
+             * BufferedImage 返回。
+             */
+            BufferedImage bi = reader.read(0, param);
+
+            // 保存新图片
+            ImageIO.write(bi, "jpg", outfile);
+        } finally {
+            if (is != null) {
+                is.close();
+            }
+            if (iis != null) {
+                iis.close();
+            }
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+        String srcImg = "D:/sm.png";
+        String tarDir = "d:/";
+//        URL url = ImageUtils.class.getResource("src-2012.jpg");
+        File srcfile = new File(srcImg);
+//        System.out.println(url);
+        System.out.println(srcfile.exists() + ", dir=" + srcfile.getParent());
+        tarDir = srcfile.getParent();
+        srcImg = srcfile.getPath();
+        System.out.println("srcImg=" + srcImg);
+        long startTime = new Date().getTime();
+        resize(srcImg, tarDir + "car_1_maxLength_1-200px.jpg", 200);
+//        Tosmallerpic(srcImg, tarDir + "car_1_maxLength_2.jpg", 0.5F);
+        resize(srcImg, tarDir + "car_1_maxLength_3.jpg", 280, 112);
+        resize(srcImg, tarDir + "car_1_maxLength_4-400x400.jpg", 220, 220);
+        resize(srcImg, tarDir + "car_1_maxLength_11-220px-yinhui.jpg", 220, 0.7F);
+//        Tosmallerpic(srcImg, tarDir + "car_1_maxLength_22.jpg", 0.5F, 0.8F);
+        resize(srcImg, tarDir + "car_1_maxLength_33.jpg", 400, 500, 0.8F);
+        System.out.println(new Date().getTime() - startTime);
+    }
+}

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

@@ -1,6 +1,6 @@
 package cn.com.ctop.kuaishou.modules.graphql.service.impl;
 
-import cn.com.ctop.common.utils.HttpUtils2;
+import cn.com.ctop.common.utils.*;
 import cn.com.ctop.kuaishou.modules.graphql.entity.*;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouUserService;
 import cn.com.ctop.kuaishou.modules.graphql.service.IKuaishouVideoService;
@@ -10,21 +10,29 @@ import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.gson.Gson;
+import org.apache.commons.io.FileUtils;
 import org.apache.http.client.CookieStore;
 import org.apache.http.impl.client.BasicCookieStore;
 import org.apache.http.impl.cookie.BasicClientCookie;
-import org.openqa.selenium.By;
-import org.openqa.selenium.Cookie;
-import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.*;
+
+import java.awt.Rectangle;
 import org.openqa.selenium.chrome.ChromeDriver;
 import org.openqa.selenium.chrome.ChromeDriverService;
 import org.openqa.selenium.chrome.ChromeOptions;
+import org.openqa.selenium.html5.Location;
+import org.openqa.selenium.interactions.Actions;
+import org.openqa.selenium.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.RemoteWebDriver;
 import org.openqa.selenium.support.ui.ExpectedConditions;
 import org.openqa.selenium.support.ui.WebDriverWait;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import sun.misc.BASE64Encoder;
 
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.io.UnsupportedEncodingException;
@@ -195,18 +203,21 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
 
     @Override
     public void adkuaishouWebLogin(String phone, String password) throws IOException {
-        ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File(chromeDriver)).usingAnyFreePort().build();
+        ChromeDriverService service = new ChromeDriverService.Builder().usingDriverExecutable(new File("D:/chromedriver.exe")).usingAnyFreePort().build();
         service.start();
-        System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
+//        System.getProperties().setProperty("webdriver.chrome.driver", chromeDriver);
         ChromeOptions chromeOptions = new ChromeOptions();
-        WebDriver webDriver = new ChromeDriver(chromeOptions);
+//        chromeOptions.addArguments("--proxy-server=http://111.231.92.21:8888");
+//        chromeOptions.addArguments("--headless");
+        chromeOptions.addArguments("--no-sandbox");
+//        chromeOptions.addArguments("--disable-gpu");
+        chromeOptions.addArguments("--window-size=1290,1080");
+        chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
+        chromeOptions.setAcceptInsecureCerts(true);
+        WebDriver webDriver = new RemoteWebDriver(service.getUrl(), chromeOptions);
+//        WebDriver webDriver = new ChromeDriver(chromeOptions);
         try {
-            chromeOptions.addArguments("--headless");
-            chromeOptions.addArguments("--no-sandbox");
-            chromeOptions.addArguments("--disable-gpu");
-            chromeOptions.addArguments("--window-size=1290,1080");
-            chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
-            chromeOptions.setAcceptInsecureCerts(true);
+
             //全局隐式等待
             webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
             //设定网址
@@ -218,7 +229,36 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
             //点击登录
             webDriver.findElement(By.className("foot")).click();
             //等待2秒用于页面加载,保证Cookie响应全部获取。
-            Thread.sleep(2000);
+
+            Thread.sleep(10000);
+//            String text = webDriver.findElement(By.tagName("iframe")).getAttribute("src");
+//            System.out.println(text);
+//            webDriver.get(text);
+
+//            System.out.println(webDriver.getPageSource());
+
+//            String src = webDriver.findElement(By.id("clickCharTips")).getAttribute("src");
+//            System.out.println(src);
+//            Actions actions = new Actions(webDriver);
+//            actions.moveToElement(webDriver.findElement(By.className("aq_icon_refresh")));
+//            actions.moveByOffset(10,10);
+//            actions.moveByOffset(100,100);
+//            actions.click();
+
+//            webDriver.switchTo().frame(webDriver.findElement(By.tagName("iframe")));
+//            File scrFile = ((TakesScreenshot)webDriver).getScreenshotAs(OutputType.FILE);
+//            WebElement iframeElement = webDriver.findElement(By.tagName("iframe"));
+//            if (iframeElement != null) {
+//                File scrFile = captureElement(webDriver.findElement(By.tagName("iframe")));
+//                String savePath = "D:/capter.png";
+//                FileUtils.copyFile(scrFile, new File(savePath));
+//                webDriver.switchTo().frame(webDriver.findElement(By.tagName("iframe")));
+//                String result = ChaojiyingUtils.process(Base64Utils.ImageToBase64(savePath));
+//                System.out.println(result);
+//                ((JavascriptExecutor) webDriver).executeScript("arguments[0].click();", webDriver.findElement(By.className("aq_icon_refresh")));
+//            }
+
+
             webDriver.get("https://b.e.kuaishou.com/#/home/profile");
             //获取Cookie并打印
             Set<Cookie> cookies = webDriver.manage().getCookies();
@@ -247,26 +287,48 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
-            webDriver.quit();
-            service.stop();
+//            webDriver.quit();
+//            service.stop();
 //            HttpUtils.cookieStore.clear();
         }
     }
 
+    public File captureElement(WebElement element) throws Exception {
+        // TODO Auto-generated method stub
+        WrapsDriver wrapsDriver = (WrapsDriver) element;
+        // 截图整个页面
+        File screen = ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.FILE);
+//        ((TakesScreenshot) wrapsDriver.getWrappedDriver()).getScreenshotAs(OutputType.)
+        String tempPath = "D:/temp.png";
+        FileUtils.copyFile(screen, new File(tempPath));
+        BufferedImage img = ImageIO.read(new File(tempPath));
+        // 获得元素的高度和宽度
+        int width = element.getSize().getWidth();
+        int height = element.getSize().getHeight();
+//        // 创建一个矩形使用上面的高度,和宽度
+        Rectangle rect = new Rectangle(width, height);
+//        // 得到元素的坐标
+        Point p = element.getLocation();
+        BufferedImage dest = img.getSubimage(p.x, p.y, rect.width, rect.height);
+        // 存为png格式
+        ImageIO.write(dest, "png", screen);
+        return screen;
+    }
     @Override
     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.addArguments("--headless");
+        chromeOptions.addArguments("--no-sandbox");
+        chromeOptions.addArguments("--disable-gpu");
+        chromeOptions.addArguments("--window-size=1290,1080");
+        chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
+        chromeOptions.setAcceptInsecureCerts(true);
         WebDriver webDriver = new ChromeDriver(chromeOptions);
         try {
-            chromeOptions.addArguments("--headless");
-            chromeOptions.addArguments("--no-sandbox");
-            chromeOptions.addArguments("--disable-gpu");
-            chromeOptions.addArguments("--window-size=1290,1080");
-            chromeOptions.addArguments("--user-agent=" + HttpUtils2.USER_AGENT);
-            chromeOptions.setAcceptInsecureCerts(true);
+
             webDriver.get("https://live.kuaishou.com/profile/" + uid);
             Thread.sleep(2000);
             webDriver.navigate().refresh();
@@ -434,6 +496,8 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
     public static void main(String[] args) {
         try {
             KuaishouWebInterfaceServiceImpl i = new KuaishouWebInterfaceServiceImpl();
+            String result = ChaojiyingUtils.process(Base64Utils.ImageToBase64("D:/capter.png"));
+            System.out.println(result);
 //            i.adkuaishouWebLogin("17611760019", "a123456");
 //            i.adkuaishouWebLogin("18822179577", "a123456");
 //            i.adkuaishouWebLogin("13552374039", "hcst2019");
@@ -452,10 +516,10 @@ public class KuaishouWebInterfaceServiceImpl implements IKuaishouWebInterfaceSer
 //            i.adkuaishouWebLogin("18811551872", "a123456");
 //            i.adkuaishouWebLogin("13552374039", "hcst2019");
 //            i.adkuaishouWebLogin("17116890601", "a123456");
-            i.adkuaishouWebLogin("18822179577", "a123456");
+//            i.adkuaishouWebLogin("18822179577", "a123456");
 
-            Thread.sleep(20000);
-            i.deleteAllComment(new HashMap<>());
+//            Thread.sleep(20000);
+//            i.deleteAllComment(new HashMap<>());
         } catch (Exception e) {
             e.printStackTrace();
         }