- 浏览: 152454 次
- 性别:
- 来自: 杭州
文章分类
最新评论
-
梁梓程:
GitHub里面的那个sand的代码可以换成java的吗?
浅入浅出游戏粒子系统 -
aa276174247:
楼主好人,求源码研究, 670205373@qq.com
基于java Red5服务器客户端视频聊天室搭起来了 -
07shou:
楼主,小弟最近在学习视频播放,有很多问题,不知可以发份代码学习 ...
基于java Red5服务器客户端视频聊天室搭起来了 -
star245:
能共享出来代码吗,liwen337@163.com
基于java Red5服务器客户端视频聊天室搭起来了 -
lf555:
楼主~~ 何时打算开源呀~~ 借鉴学习下~
打算实现开源网页游戏框架openjpfgame(Java Php flex game),目前实现部分
try
{
mainPage = webClient.getPage(url);
} catch (Exception e)
{
log.error(e.getMessage(), e);
}
if (mainPage != null)
{
HtmlElement paginationContainer = mainPage
.getElementById("paginationContainer");
if (paginationContainer != null)
{
url = url + "/all-1";
try
{
mainPage = webClient.getPage(url);
} catch (Exception e)
{
log.error(e.getMessage(), e);
}
}
HtmlElement categories = mainPage.getElementById("categories");
if (categories == null)
{
HtmlElement products = mainPage.getElementById("products");
if(products!=null)
{
List<HtmlElement> productDivList = products.getElementsByTagName("div");
if(productDivList!=null&&productDivList.size()>0)
{
for(HtmlElement proDiv:productDivList)
{
List<HtmlElement> subList = proDiv.getElementsByTagName("div");
if(subList!=null)
{
for(HtmlElement dt:subList)
{
String classt = dt.getAttribute("class");
if (classt != null && classt.equals("productImg"))
{
List<HtmlElement> subAList = proDiv.getElementsByTagName("a");
if(subAList!=null&&subAList.size()>0)
{
HtmlElement ae=subAList.get(0);
String href = ae.getAttribute("href");
thirdPageUrls.add(href);
}
break;
}
}
}
}
}
}
}
else
{
List<HtmlElement> divList = categories.getElementsByTagName("div");
if (divList != null && divList.size() > 0)
{
for (HtmlElement div : divList)
{
List<HtmlElement> tempDivs = div
.getElementsByTagName("div");
if (tempDivs != null && tempDivs.size() > 0)
{
for (HtmlElement div1 : tempDivs)
{
List<HtmlElement> aList = div1
.getElementsByTagName("a");
HtmlAnchor a = (HtmlAnchor) aList
.get(0);
String link = a.getHrefAttribute();
secondPageUrls.add(link);
}
}
}
}
}
}
}
}
log.error("第二层抓取结束..........");
log.error("目前抓取到的第二层URL个数为:"+secondPageUrls.size());
int count=0;
for (String url : secondPageUrls)
{
count++;
log.error("正在抓取第二层的第"+count+"个URL:"+url);
HtmlPage mainPage = null;
try
{
mainPage = webClient.getPage(url);
} catch (Exception e)
{
log.error(e.getMessage(), e);
}
log.error("抓取URL完成:"+url+",正在分析URL"+url+"+结果的URL");
if (mainPage != null)
{
HtmlElement paginationContainer = mainPage
.getElementById("paginationContainer");
if (paginationContainer != null)
{
url = url + "/all-1";
}
HtmlElement products = mainPage.getElementById("products");
if (products != null)
{
List<HtmlElement> list = products
.getElementsByTagName("div");
;
if (list == null || list.size() == 0)
{
continue;
}
for (HtmlElement h : list)
{
String cls = h.getAttribute("class");
if (cls == null || !cls.equals("productName"))
{
continue;
}
List<HtmlElement> links = h.getElementsByTagName("a");
if (links != null && links.size() > 0)
{
HtmlAnchor htmlAnchor = (HtmlAnchor) links.get(0);
String linkStr = htmlAnchor.getHrefAttribute();
thirdPageUrls.add(linkStr);
log.error(linkStr);
}
}
}
}
}
log.error("第二层抓取结束..........");
secondPageUrls.clear();
secondPageUrls = null;
count=0;
log.error("目前抓取到的第三层URL个数为:"+thirdPageUrls.size());
String urlPrix="http://www.swarovski-crystallized.com/jewelry/us/";
for (String url : thirdPageUrls)
{
count++;
log.error("正在抓取第三层的第"+count+"个URL:"+url);
HtmlPage mainPage = null;
try
{
mainPage = webClient.getPage(url);
} catch (Exception e)
{
log.error(e.getMessage(), e);
}
if (mainPage != null)
{
log.error("抓取URL完成:"+url+",正在分析URL"+url+"+结果");
int indexC=url.indexOf(urlPrix);
int indexD=url.indexOf("?");
String dirStr=url.substring(indexC+urlPrix.length(), indexD);
String regEx = "/";
// Pattern p = Pattern.compile(regEx);
// Matcher m = p.matcher(dirStr);
//哦哦哦,建立文件夹准备把抓到数据放在里面
dirStr=replece( regEx,"\\\\",dirStr);
dirStr = "D:\\swaroski\\"+dirStr;
File file = new File(dirStr);
if(file.isDirectory())
{
dirStr=dirStr+"\\"+count;
file = new File(dirStr);
}
file.mkdirs();
Product product=new Product();
product.setLocalDir(dirStr);
product.setPageUrl(url);
HtmlElement rightCol = mainPage.getElementById("rightCol");
String title = null;
String description = null;
String packingUnit = null;
if (rightCol != null)
{
HtmlElement headlineDiv = rightCol
.getElementById("headline");
if (headlineDiv != null)
。。。。。。。。。。。。。。。。。。。。。。。。
log.error("完成:"+url+",分析结果");
try
{
swaroSkiDAO.addProduct(product);
} catch (Exception e)
{
log.error(e.getMessage(), e);
}
log.error("完成保存结果");
for(String downloadUrl:resourceUrlList)
{
int index6=downloadUrl.lastIndexOf("/");
String fileName=downloadUrl.substring(index6+1);
String dirStr2=dirStr+"\\"+fileName;
File storeFile = new File(fileName);
if(storeFile.exists())
{
continue;
}
SaveFileThread runable=new SaveFileThread(dirStr2,downloadUrl,sem);
pools.submit(runable);
log.error("开始提交下载文件:"+downloadUrl);
try
{
Thread.sleep(2500);
} catch (InterruptedException e)
{
}
}
//啊哈哈,这个就是去拿下图片和动画的线程,结束
class SaveFileThread implements Runnable
{
private String fileName;
private String downloadUrl;
private Semaphore sem;
public SaveFileThread(String fileName,String downloadUrl,Semaphore sem)
{
this.fileName=fileName;
this.downloadUrl=downloadUrl;
this.sem=sem;
}
public void run()
{
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(downloadUrl);
FileOutputStream output=null;
try
{
client.executeMethod(get);
File storeFile = new File(fileName);
output = new FileOutputStream(storeFile);
output.write(get.getResponseBody());
output.flush();
} catch (Exception e)
{
log.error(e.getMessage(), e);
}
发表评论
-
java高速生成大文件的MD5算法
2012-10-27 00:28 0java快速生成大文件的MD5算法import java.io ... -
教你轻松拿下百度音乐播放器mp3地址
2010-09-28 21:23 1050教你轻松拿下百度音乐播放器mp3地址----ldfu2010 ... -
周会&惩罚激励制度
2012-03-21 13:41 0周会 个人很反感开会,因为之前参与过的会议,有80%都是没有 ... -
负载均衡--大型在线系统实现的关键(下篇)
2012-03-21 12:42 0在网络应用中,“负载 ... -
技术主义者的网游观点
2012-03-21 12:06 0大概一年多或者更早以前,我就想过是否能实现单一游戏世界平均同时 ... -
C++中使用Lua脚本 和lua中调用c的方法
2012-03-21 12:04 0参考http://blog.csdn.net/kun12345 ... -
超大地图MMORPG的场景管理
2012-03-21 12:03 0超大地图MMORPG的场景管 ... -
MMORPG开发入门
2012-03-21 11:59 0作者: Radu Privantu 译者:pAnic 20 ... -
服务器宕机
2012-03-21 11:53 0服务器宕机 我不得不承认,我的能力不足以写出一个100% ... -
从腾讯QQgame高性能服务器集群架构看“分而治之”与“自治”等分布式架构设计原则
2012-03-21 11:28 0从腾讯QQgame高性能服务器集群架构看“分而治之”与“自治 ... -
一种经典的服务器架构
2012-03-21 11:27 0一种经典的服务器架构 ... -
一个AS3 socket解码设计的错误思路
2012-03-20 17:34 0一个AS3 socket解码设计的错误思路 作者:闪刀 ... -
FLASH端SOCKET连接C++服务端代码
2012-03-20 16:55 0FLASH端S 最近在开发一个休闲类的游 ... -
java并发分析as3中的无用css样式
2012-03-12 16:19 0java并发分析as3中的无用css样式 -
java连接SSH服务器并执行shell命令
2012-03-09 18:27 0前要通过java连接到SSH服务器并执行一些linux配置命令 ... -
ant + jsch 远程发布web工程
2012-03-09 18:08 0<?xml version="1.0&quo ... -
nio支持epoll
2012-03-05 11:52 0<project name="xiyou&qu ... -
游戏中用户点击不可达地点引起寻路循环,游戏停顿问题解决
2011-11-20 18:36 1818游戏中用户点击不可达地点引起寻路循环,游戏停顿问题解决 ... -
apache common-dbutils 的使用
2011-06-08 14:46 0package demo.dbutilsdemo; i ... -
用Varnish搭建Cache服务
2011-06-07 15:57 0用Varnish搭建Cache服务器 - [技术笔记] ...
相关推荐
NULL 博文链接:https://caerun.iteye.com/blog/1338956
<artifactId>htmlunit</artifactId> <version>2.48.0</version> </dependency> 概述 HtmlUnit是“用于Java程序的GUI更少的浏览器”。 它为HTML文档建模,并提供一个API,使您可以调用页面,填写表单,单击链接等,...
HtmlUnitDriver ... < artifactId>htmlunit-driver</ artifactId> < version>2.49.1</ version> </ dependency> 用法 简单的 您可以简单地使用HtmlUnit驱动程序类中的构造函数之一 // simple case - no j
htmlunit头条搜索操作
通过htmlunit 下载网站资源的简单示例 htmlunit 是一款开源的java 页面分析工具,读取页面后,可以有效的使用htmlunit分析页面上的内容。 项目可以模拟浏览器运行,被誉为java浏览器的开源实现。是一个没有界面的...
HTTP 协议可能是现在 Internet 上...HttpClient 已经应用在很多的项目中,比如 Apache Jakarta 上很著名的另外两个开源项目 Cactus 和 HTMLUnit 都使用了 HttpClient。现在HttpClient最新版本为 HttpClient 4.2 (GA)
HttpClient 是 Apache Jakarta Common 下的子项目,可以用来提供高效的、最新的、...HttpClient 已经应用在很多的项目中,比如 Apache Jakarta 上很著名的另外两个开源项目 Cactus 和 HTMLUnit 都使用了 HttpClient。
针对 httpclient4.* 绕验证码获取公司信息 包括 jsoup网页信息的爬虫及htmlUnit对动态网站信息的抓取
HTTP 协议可能是现在 Internet 上使用得最多、最重要的协议了,越来越多的 Java ...HttpClient 已经应用在很多的项目中,比如 Apache Jakarta 上很著名的另外两个开源项目 Cactus 和 HTMLUnit 都使用了 HttpClient。
htmlUnit所需工具包,htmlUnit,htmlUnit,htmlUnit,htmlUnit,htmlUnit
htmlunit2.8 + jsoup1.7各种网站上的数据抓取。
HTTP 协议可能是现在 Internet 上使用得最多、最重要的协议了,越来越多的 Java ...HttpClient 已经应用在很多的项目中,比如 Apache Jakarta 上很著名的另外两个开源项目 Cactus 和 HTMLUnit 都使用了 HttpClient,
HTTP 协议可能是现在 Internet 上使用...HttpClient 已经应用在很多的项目中,比如 Apache Jakarta 上很著名的另外两个开源项目 Cactus 和 HTMLUnit 都使用了 HttpClient。现在HttpClient最新版本为 HttpClient 4.5 .6
HttpClient已经应用在很多的项目中,比如Apache Jakarta上很著名的另外两个开源项目Cactus和HTMLUnit都使用了HttpClient。 下载地址: http://hc.apache.org/downloads.cgi 1.2特性 1. 基于标准、纯净的java语言。...
HTTP 协议可能是现在 Internet 上使用得...HttpClient 已经应用在很多的项目中,比如 Apache Jakarta 上很著名的另外两个开源项目 Cactus 和 HTMLUnit 都使用了 HttpClient。现在HttpClient最新版本为 HttpClient 4.5
java 开发 htmlunit官方jar包和api文档
HttpClient已经应用在很多的项目中,比如Apache Jakarta上很著名的另外两个开源项目Cactus和HTMLUnit都使用了HttpClient。 适用人群:JavaWeb开发者 使用场景:在Java后端程序中,模拟浏览器端进行Web请求。 其它:...
HttpClient 已经应用在很多的项目中,比如 Apache Jakarta 上很著名的另外两个开源项目 Cactus 和 HTMLUnit 都使用了 HttpClient。现在HttpClient最新版本为 HttpClient 4.5 (GA) (2015-09-11)
htmlunit jar zip 2.23 用于html爬虫