- 浏览: 360543 次
- 性别:
- 来自: 四川
文章分类
- 全部博客 (247)
- 数据库以及sql (11)
- java (48)
- 爬虫学习 (20)
- java编程 (28)
- python编程以及安装和配置 (27)
- oracle数据库 (32)
- mongodb基本操作 (4)
- linux学习 (7)
- easyUI (2)
- nodeJs (8)
- python学习 (16)
- 其他 (13)
- hadoop (1)
- svn (1)
- 汉字 (1)
- windows (2)
- jsp (5)
- fiddler (1)
- ETL (1)
- teamviewer (1)
- maven (4)
- GIT (2)
- datagrip (1)
- ocr (1)
- redis (3)
- mysql (3)
- linux (1)
- 数据服务 (0)
最新评论
应用场景: 识别网页验证码,破解并登陆页面
难点:验证码直接下载的话会造成下载的图片和网站的图片不一致, 原因(验证码的图片地址访问一次就会随机生成一个验证码),所以我采用模拟器截图的方式
代码:
package com.teamdev.jxbrowser.chromium.demoJD.yyzz;
import java.awt.BorderLayout;
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.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserPreferences;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.LoggerProvider;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
public class saveImage {
private static final Color White = null;
public static void main(String[] args) {
LoggerProvider.getBrowserLogger().setLevel(Level.SEVERE);
LoggerProvider.getIPCLogger().setLevel(Level.SEVERE);
LoggerProvider.getChromiumProcessLogger().setLevel(Level.SEVERE);
Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
BrowserPreferences preferences = browser.getPreferences();
preferences.setImagesEnabled(false);
int viewWidth = 1280;
int viewHeight = 1000;
// Resize view to the required size
view.setBounds(new Rectangle(viewWidth, viewHeight));
// Wait until web page is loaded completely
invokeAndWaitReady(browser,new jd_yyzz().new ViewThread(browser, "https://mall.jd.com/showLicence-652046.html"));
JSValue bodyHeight = null;
int firstHeight = 400;
int nowHeight = 400;
while (firstHeight != nowHeight) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
firstHeight = nowHeight;
bodyHeight = browser.executeJavaScriptAndReturnValue("document.body.scrollHeight");
//nowHeight = 900;
for (int i = firstHeight; i < nowHeight; i = i + 300) {
browser.executeJavaScriptAndReturnValue("window.scrollTo(0,"+ i + ")");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
System.out.println(firstHeight + ":" + nowHeight);
}
viewHeight = nowHeight + 50;
view.setBounds(new Rectangle(viewWidth, viewHeight));
System.out.println("高度:" + viewHeight);
try {
Thread.sleep(1000 * 1);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
bodyHeight = browser.executeJavaScriptAndReturnValue("document.body.scrollHeight");
System.out.println("高度------------------:" + bodyHeight);
int viewHeight_new = ((Number) bodyHeight.getNumber()).intValue() + 50;
if (viewHeight_new > viewHeight) {
System.out.println("新高度------------------:" + viewHeight_new);
}
Image image = view.getImage();
BufferedImage bufferedImage = new BufferedImage(100, 50,BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
Double scale = 1.0 / view.getDeviceScaleFactor();
graphics.scale(scale, scale);
graphics.drawImage(image,-585, -355, image.getWidth(view), image.getHeight(view),White, null);
try {
String path = "f://shopdetails.jpg";
ImageIO.write(bufferedImage, "JPG", new File(path));
bufferedImage = null;
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 线程
* */
class ViewThread extends Thread {
Browser browser;
String openUrl;
public ViewThread(Browser browser, String openUrl) {
this.browser = browser;
this.openUrl = openUrl;
}
public void run() {
browser.loadURL(openUrl);
}
}
/**
* 模拟器加载url
* */
public static void invokeAndWaitReady(Browser browser, Runnable runnable) {
final CountDownLatch latch = new CountDownLatch(1);
LoadAdapter listener = new LoadAdapter() {
@Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
latch.countDown();
}
}
};
browser.addLoadListener(listener);
try {
runnable.run();
try {
if (!latch.await(60, TimeUnit.SECONDS)) {
// throw new RuntimeException(new TimeoutException());
}
} catch (InterruptedException ignore) {
ignore.printStackTrace();
Thread.currentThread().interrupt();
}
} finally {
browser.removeLoadListener(listener);
}
}
}
难点:验证码直接下载的话会造成下载的图片和网站的图片不一致, 原因(验证码的图片地址访问一次就会随机生成一个验证码),所以我采用模拟器截图的方式
代码:
package com.teamdev.jxbrowser.chromium.demoJD.yyzz;
import java.awt.BorderLayout;
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.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import com.teamdev.jxbrowser.chromium.Browser;
import com.teamdev.jxbrowser.chromium.BrowserPreferences;
import com.teamdev.jxbrowser.chromium.JSValue;
import com.teamdev.jxbrowser.chromium.LoggerProvider;
import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
import com.teamdev.jxbrowser.chromium.swing.BrowserView;
public class saveImage {
private static final Color White = null;
public static void main(String[] args) {
LoggerProvider.getBrowserLogger().setLevel(Level.SEVERE);
LoggerProvider.getIPCLogger().setLevel(Level.SEVERE);
LoggerProvider.getChromiumProcessLogger().setLevel(Level.SEVERE);
Browser browser = new Browser();
BrowserView view = new BrowserView(browser);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.add(view, BorderLayout.CENTER);
frame.setSize(700, 500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
BrowserPreferences preferences = browser.getPreferences();
preferences.setImagesEnabled(false);
int viewWidth = 1280;
int viewHeight = 1000;
// Resize view to the required size
view.setBounds(new Rectangle(viewWidth, viewHeight));
// Wait until web page is loaded completely
invokeAndWaitReady(browser,new jd_yyzz().new ViewThread(browser, "https://mall.jd.com/showLicence-652046.html"));
JSValue bodyHeight = null;
int firstHeight = 400;
int nowHeight = 400;
while (firstHeight != nowHeight) {
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
firstHeight = nowHeight;
bodyHeight = browser.executeJavaScriptAndReturnValue("document.body.scrollHeight");
//nowHeight = 900;
for (int i = firstHeight; i < nowHeight; i = i + 300) {
browser.executeJavaScriptAndReturnValue("window.scrollTo(0,"+ i + ")");
try {
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
System.out.println(firstHeight + ":" + nowHeight);
}
viewHeight = nowHeight + 50;
view.setBounds(new Rectangle(viewWidth, viewHeight));
System.out.println("高度:" + viewHeight);
try {
Thread.sleep(1000 * 1);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
bodyHeight = browser.executeJavaScriptAndReturnValue("document.body.scrollHeight");
System.out.println("高度------------------:" + bodyHeight);
int viewHeight_new = ((Number) bodyHeight.getNumber()).intValue() + 50;
if (viewHeight_new > viewHeight) {
System.out.println("新高度------------------:" + viewHeight_new);
}
Image image = view.getImage();
BufferedImage bufferedImage = new BufferedImage(100, 50,BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphics = (Graphics2D) bufferedImage.getGraphics();
Double scale = 1.0 / view.getDeviceScaleFactor();
graphics.scale(scale, scale);
graphics.drawImage(image,-585, -355, image.getWidth(view), image.getHeight(view),White, null);
try {
String path = "f://shopdetails.jpg";
ImageIO.write(bufferedImage, "JPG", new File(path));
bufferedImage = null;
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* 线程
* */
class ViewThread extends Thread {
Browser browser;
String openUrl;
public ViewThread(Browser browser, String openUrl) {
this.browser = browser;
this.openUrl = openUrl;
}
public void run() {
browser.loadURL(openUrl);
}
}
/**
* 模拟器加载url
* */
public static void invokeAndWaitReady(Browser browser, Runnable runnable) {
final CountDownLatch latch = new CountDownLatch(1);
LoadAdapter listener = new LoadAdapter() {
@Override
public void onFinishLoadingFrame(FinishLoadingEvent event) {
if (event.isMainFrame()) {
latch.countDown();
}
}
};
browser.addLoadListener(listener);
try {
runnable.run();
try {
if (!latch.await(60, TimeUnit.SECONDS)) {
// throw new RuntimeException(new TimeoutException());
}
} catch (InterruptedException ignore) {
ignore.printStackTrace();
Thread.currentThread().interrupt();
}
} finally {
browser.removeLoadListener(listener);
}
}
}
发表评论
-
是什么java多态
2018-11-14 13:43 581Java多态 例1.1+1=2 例2."1&quo ... -
经纬度转换
2018-09-25 13:57 0package com.teamdev.jxbrowser.c ... -
java连接池技术
2018-09-04 14:26 311转:https://www.cnblogs.com/xdp-g ... -
java 提取url字符串中的域名
2018-08-30 15:24 7273package com.teamdev.jxbrowser.c ... -
java多线程中锁(lock)、wait、notify()的使用
2018-07-13 11:31 5623package com.kai.多线程间的通信; impor ... -
java多线程间的通信实例
2018-07-13 11:00 1323----线程间的通信 public class ListAd ... -
volatile关键字
2018-07-12 11:20 573volatile:使变量在多个线程间可见 public c ... -
java根据百度url获取真正的网页地址
2018-07-09 11:26 912/** * 根据百度url,获取原本url * @th ... -
java中的base64字符流与图片的相互转换
2018-06-29 13:27 1175//base64字符串转化成图片 public sta ... -
java去除图片水印的解决办法
2018-06-28 10:54 3174原文地址:http://www.oicqzone.com/pc ... -
java中的中文字符转URLEncode
2018-06-26 11:26 723String urlTypeName =java.net.UR ... -
java下载图片到本地实例
2018-06-25 15:34 1290public static void main(String[ ... -
Myeclipse中如何更改jsp默认的打开方式
2018-05-04 17:44 5541.打开myeclipse 2.点击上方的 window-&g ... -
java三大范式
2018-05-02 09:50 669参考地址:https://www.cnblogs.com/ja ... -
请求中设置代理IP
2018-04-18 16:24 877(不能直接JVM设置代理 System.getProperti ... -
java获取当前时间的时间戳
2018-04-08 09:25 1406package com.teamdev.jxbrowser.c ... -
java四种线程池实例 (kaigege)
2018-03-28 11:03 633Java通过Executors提供四种线程池: 1.newCa ... -
java获取IP地址(windos,linux)皆可
2018-03-28 09:44 722package com.teamdev.jxbrowser.c ... -
post 请求
2018-02-05 16:32 465public static void trustEveryo ... -
java robot控制鼠标和键盘(笔记本中打印 i love you)(滑动)
2018-01-25 16:57 2017package robot_java; import jav ...
相关推荐
包含5个识别图片验证码的类,分别对应不同5种不同的验证码 其中用了两种不同的实现方式(截取采样像素比对+Tesseract-OCR识别) 附带一个图像指纹类(判定图片相似度)和一个寻找联通线的类(八皇后算法实现)
java将视频定时截取图片并保存
java 处理图片大小等比例缩放;图片裁剪;支持图片压缩不失真;支持图片添加水印;支持动态图的处理;支持自定义图片大小的转换 等 压缩包中内附使用说明
这个示例实现截取指定区域的图片 当触摸背景图像的某一点时,会将以该点为左上顶点的一个正方形区域复制到另一个100*100的ImageView图片中
该示例在java后台运行,采用phantomjs截取页面存为图片。包括自定义高度全屏截取和div截取两种方式。
截取视频中的某一帧的图像含ffmpeg.jar 和调用方法和类
<groupId>org.bytedeco <artifactId>javacpp-presets <version>1.4.3 </dependency>
java 拍照 功能,调用链接的摄像头,可以远程访问该拍照页面并且进行拍照
功能说明:java视频剪辑,可按时间将视频截取为子视频。 使用说明:解压导入eclipse后执行main方法即可。
java调用opencv利用霍夫圆定位查找印章,并返回质心坐标和半径以达到截取印章的目的
PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试PHP 去HTML,截取指定汉字正则表达试...
Python - 截取指定帧数间隔指定大小的视频,并保存图片到指定位置; 详细请查看https://blog.csdn.net/tanghong1996/article/details/88395372
java 字符串截取工具类java 字符串截取工具类
android 截取短信验证码自动输入Demo 关注我的微博:http://blog.csdn.net/yayun0516 上面有文章介绍哦!
该工具类用于java代码对图片的截取,按照上下左右边距的百分比截取,然后返回被截取之后图片信息的byte数组,用户可以将byte数组,用fileoutputStream保存在指定的目录
Java 实现头像的截取,并上传头像。 项目使用说明: 1,要下载maven ,并配置环境变量 2,将image.jsp里面的图片换成你的本地图片 3,通过maven 打包。 4,部署到tomcat.打开image.jsp页面就可以验证了。 ...
利用excel模板(设置背景图、网格显示与否、标题字体颜色等) 执行py文件,通过python自动化填充数据,并截取图片 方便快捷办公,简化操作流程
可以实现视频截图,视频剪辑,视频转换,支持编码广范,速度极快,支持windows linux平台
获取网页上验证码图片,保存在本地。获取网页上验证码图片,保存在本地。
winpcap截取指定ip网络数据包并保存 winpcap截取指定ip网络数据包并保存 winpcap截取指定ip网络数据包并保存