- 浏览: 207311 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
jccmjl:
1222222222222222
htmlunit分页爬去数据实现 -
jccmjl:
os586 写道attr("checked" ...
jquery根据对象选中 radio 和select -
os586:
attr("checked",true); ...
jquery根据对象选中 radio 和select
package com.htmlunit.sky;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
/**
* 运用htmlUnit爬网页
*
* @author liming
*/
public class SkyHtmlUnit {
// 充值密码
private static final String transPassword = "XXXX";
// 用户名
private static final String userName = "xxx";
// 密码
private static final String userPassword = "XXXX";
/**
* 充值
*
* @param transNumber
* 被充值用户号码
* @param transAmount
* 充值金额
*/
public static boolean recharge(String transNumber, String transAmount) {
boolean bool = false;
try {
BigDecimal b = new BigDecimal(transAmount);
b = b.setScale(0, BigDecimal.ROUND_DOWN);
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
List<String> collectedAlerts = new ArrayList<String>();
client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
HtmlPage page1 = (HtmlPage) client
.getPage("http://XXX/vams/");
HtmlForm form = (HtmlForm) page1.getForms().get(0);
HtmlTextInput username = (HtmlTextInput) form
.getInputByName("login:userName");
HtmlPasswordInput password = (HtmlPasswordInput) form
.getInputByName("login:password");
username.setValueAttribute(userName);
password.setValueAttribute(userPassword);
form.getInputByName("login:j_id_jsp_28762255_4").click();
client.setJavaScriptEnabled(true);
String Recharge = "http://XXX/vams/WebPay/WebTrans.faces";
HtmlPage Recharge1 = (HtmlPage) client.getPage(Recharge);
HtmlForm RechargeForm = (HtmlForm) Recharge1.getForms().get(0);
HtmlTextInput number = (HtmlTextInput) RechargeForm
.getInputByName("webPayment:transNumber");
HtmlTextInput transAmountt = (HtmlTextInput) RechargeForm
.getInputByName("webPayment:transAmount");
HtmlPasswordInput transPass = (HtmlPasswordInput) RechargeForm
.getInputByName("webPayment:transPassword");
// 设置充值密码
transPass.setValueAttribute(transPassword);
// 设置充值金额
transAmountt.setValueAttribute(b.toString());
// 设置充值号码
number.setValueAttribute(transNumber);
RechargeForm.getInputByName("webPayment:j_id_jsp_427518967_10")
.click();
String returnvalue = collectedAlerts.get(0);
if (returnvalue.equals("充值成功!")) {
bool = true;
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("**********充值结束*******");
return bool;
}
/**
* 充值结果查询
*
* @param payNoValue
* 充值号码
* @param beforeTime
* 充值时间前 格式YYYYMMdd
* @param afterTime
* 充值时间后 格式YYYYMMdd
* @param rechargeAmount
* 充值金额
* @throws ParseException
*/
public static List<RechargeBean> getRechargeList(String payNoValue,
String beforeTime, String afterTime, String rechargeAmount
) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat formatX = new SimpleDateFormat("yyyy/MM/dd");
String beforeT = "";
String afterT = "";
if (beforeTime != null && !afterTime.equals("")) {
beforeT = formatX.format(format.parse(beforeTime));
}
if (afterTime != null && !afterTime.equals("")) {
afterT = formatX.format(format.parse(afterTime));
}
// 存储集合
List<RechargeBean> list = new ArrayList<RechargeBean>();
try {
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
HtmlPage page1 = (HtmlPage) client
.getPage("http://XXX/vams/");
HtmlForm form = (HtmlForm) page1.getForms().get(0);
HtmlTextInput username = (HtmlTextInput) form
.getInputByName("login:userName");
HtmlPasswordInput password = (HtmlPasswordInput) form
.getInputByName("login:password");
username.setValueAttribute(userName);
password.setValueAttribute(userPassword);
form.getInputByName("login:j_id_jsp_28762255_4").click();
client.setJavaScriptEnabled(true);
String Recharge = "http://XXX/vams/WebPay/WebPaySearch.faces?showType=2";
HtmlPage Recharge1 = (HtmlPage) client.getPage(Recharge);
HtmlForm rechargeForm = (HtmlForm) Recharge1.getForms().get(0);
// 充值号码
HtmlTextInput payNo = (HtmlTextInput) rechargeForm
.getInputByName("form1:payNo");
payNo.setValueAttribute(payNoValue);
// 充值时间:
HtmlTextInput j_id_jsp_1155368641_9 = (HtmlTextInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_9");
j_id_jsp_1155368641_9.setValueAttribute(beforeT);
HtmlTextInput j_id_jsp_1155368641_11 = (HtmlTextInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_11");
j_id_jsp_1155368641_11.setValueAttribute(afterT);
// 充值金额
HtmlTextInput j_id_jsp_1155368641_13 = (HtmlTextInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_13");
j_id_jsp_1155368641_13.setValueAttribute(rechargeAmount);
// button
HtmlSubmitInput button1 = (HtmlSubmitInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_32");
HtmlPage page12 = (HtmlPage) button1.click();
HtmlForm aa = page12.getForms().get(0);
int divSize = aa.getByXPath("//div[@id='zhu1']").size();
if (divSize > 1) {
HtmlDivision div = (HtmlDivision) aa.getByXPath(
"//div[@id='zhu1']").get(1);
String aad = div.asText();
int pageNumber = (Integer
.parseInt(aad.split("共")[2].split("页")[0].trim()));
Map<String, String[]> map = new HashMap<String, String[]>();
int key = 1;
for (int i = 0; i < pageNumber; i++) {
if (i == 0) {
DomNodeList<HtmlElement> tables = page12
.getElementsByTagName("table");
final HtmlTable table = (HtmlTable) tables.get(tables
.size() - 1);
for (final HtmlTableRow row : table.getBodies().get(0).getRows()) {
String[] alertPring = new String[7];
int d = 0;
for (final HtmlTableCell cell : row.getCells()) {
alertPring[d] = cell.asText();
d++;
}
map.put(key +"", alertPring);
key++;
}
} else {
HtmlPage ahtmpr = div.getHtmlElementsByTagName("a")
.get(3).click();
DomNodeList<HtmlElement> tables2 = ahtmpr
.getElementsByTagName("table");
final HtmlTable table = (HtmlTable) tables2.get(tables2
.size() - 1);
for (final HtmlTableRow row : table.getBodies().get(0)
.getRows()) {
String[] alertPring = new String[7];
int d = 0;
for (final HtmlTableCell cell : row.getCells()) {
alertPring[d] = cell.asText();
d++;
}
map.put(key +"", alertPring);
key++;
}
}
}
Set<String> keyV = map.keySet();
Iterator<String> it2 = keyV.iterator();
while (it2.hasNext()) {
RechargeBean bean = new RechargeBean();
String[] values = map.get(it2.next());
for (int i = 0; i < values.length; i++) {
bean.setId(values[0]);
bean.setDate(values[1]);
bean.setNumber(values[2]);
bean.setAmount(values[3]);
bean.setaType(values[4]);
bean.setsType(values[5]);
bean.setCgType(values[6]);
}
list.add(bean);
}
}
System.out.println("********充值结果查询结束***********");
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* 返回代理商余额
*/
public static String getBalance() {
String balance = "";
try {
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
HtmlPage page1 = (HtmlPage) client
.getPage("http://XXX/vams/");
HtmlForm form = (HtmlForm) page1.getForms().get(0);
HtmlTextInput username = (HtmlTextInput) form
.getInputByName("login:userName");
HtmlPasswordInput password = (HtmlPasswordInput) form
.getInputByName("login:password");
username.setValueAttribute(userName);
password.setValueAttribute(userPassword);
form.getInputByName("login:j_id_jsp_28762255_4").click();
client.setJavaScriptEnabled(true);
String Recharge = "http://XXX/vams/WebPay/WebPayRemainSearch.faces";
HtmlPage Recharge1 = (HtmlPage) client.getPage(Recharge);
HtmlForm rechargeForm = (HtmlForm) Recharge1.getForms().get(0);
// button按钮请求
HtmlSubmitInput button1 = (HtmlSubmitInput) rechargeForm
.getInputByName("j_id_jsp_1894475275_1:j_id_jsp_1894475275_32");
HtmlPage page3 = (HtmlPage) button1.click();
DomNodeList<HtmlElement> tables = page3
.getElementsByTagName("table");
final HtmlTable table = (HtmlTable) tables.get(tables.size() - 1);
for (final HtmlTableRow row : table.getBodies().get(0).getRows()) {
int i = 0;
for (final HtmlTableCell cell : row.getCells()) {
if (i == 7) {
HtmlPage page = cell.getHtmlElementsByTagName("a").get(
0).click();
DomNodeList<HtmlElement> pagezhu = (DomNodeList<HtmlElement>) page
.getElementById("zhu1").getElementsByTagName(
"td");
for (int j = 1; j < pagezhu.getLength(); j++) {
balance = pagezhu.get(1).asText();
}
}
i++;
}
}
System.out.println("*************代理商余额查询结束***********");
} catch (Exception e) {
e.printStackTrace();
}
return balance;
}
public static void main(String[] args) throws ParseException {
// 充值结果查询
// 201120619
List<RechargeBean> list = getRechargeList("", "", "", "");
for (int i = 0; i < list.size(); i++) {
RechargeBean bean = list.get(i);
System.out.println(bean.getDate());
}
// getRechargeList("", "", "", "", "");
// 查询余额
// System.out.println(getBalance());
// 进行充值
// System.out.println(recharge("18911019001", ""));
}
}
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.gargoylesoftware.htmlunit.BrowserVersion;
import com.gargoylesoftware.htmlunit.CollectingAlertHandler;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.DomNodeList;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlElement;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.gargoylesoftware.htmlunit.html.HtmlPasswordInput;
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
import com.gargoylesoftware.htmlunit.html.HtmlTable;
import com.gargoylesoftware.htmlunit.html.HtmlTableCell;
import com.gargoylesoftware.htmlunit.html.HtmlTableRow;
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
/**
* 运用htmlUnit爬网页
*
* @author liming
*/
public class SkyHtmlUnit {
// 充值密码
private static final String transPassword = "XXXX";
// 用户名
private static final String userName = "xxx";
// 密码
private static final String userPassword = "XXXX";
/**
* 充值
*
* @param transNumber
* 被充值用户号码
* @param transAmount
* 充值金额
*/
public static boolean recharge(String transNumber, String transAmount) {
boolean bool = false;
try {
BigDecimal b = new BigDecimal(transAmount);
b = b.setScale(0, BigDecimal.ROUND_DOWN);
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
List<String> collectedAlerts = new ArrayList<String>();
client.setAlertHandler(new CollectingAlertHandler(collectedAlerts));
HtmlPage page1 = (HtmlPage) client
.getPage("http://XXX/vams/");
HtmlForm form = (HtmlForm) page1.getForms().get(0);
HtmlTextInput username = (HtmlTextInput) form
.getInputByName("login:userName");
HtmlPasswordInput password = (HtmlPasswordInput) form
.getInputByName("login:password");
username.setValueAttribute(userName);
password.setValueAttribute(userPassword);
form.getInputByName("login:j_id_jsp_28762255_4").click();
client.setJavaScriptEnabled(true);
String Recharge = "http://XXX/vams/WebPay/WebTrans.faces";
HtmlPage Recharge1 = (HtmlPage) client.getPage(Recharge);
HtmlForm RechargeForm = (HtmlForm) Recharge1.getForms().get(0);
HtmlTextInput number = (HtmlTextInput) RechargeForm
.getInputByName("webPayment:transNumber");
HtmlTextInput transAmountt = (HtmlTextInput) RechargeForm
.getInputByName("webPayment:transAmount");
HtmlPasswordInput transPass = (HtmlPasswordInput) RechargeForm
.getInputByName("webPayment:transPassword");
// 设置充值密码
transPass.setValueAttribute(transPassword);
// 设置充值金额
transAmountt.setValueAttribute(b.toString());
// 设置充值号码
number.setValueAttribute(transNumber);
RechargeForm.getInputByName("webPayment:j_id_jsp_427518967_10")
.click();
String returnvalue = collectedAlerts.get(0);
if (returnvalue.equals("充值成功!")) {
bool = true;
}
} catch (Exception e) {
e.printStackTrace();
}
System.out.println("**********充值结束*******");
return bool;
}
/**
* 充值结果查询
*
* @param payNoValue
* 充值号码
* @param beforeTime
* 充值时间前 格式YYYYMMdd
* @param afterTime
* 充值时间后 格式YYYYMMdd
* @param rechargeAmount
* 充值金额
* @throws ParseException
*/
public static List<RechargeBean> getRechargeList(String payNoValue,
String beforeTime, String afterTime, String rechargeAmount
) throws ParseException {
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat formatX = new SimpleDateFormat("yyyy/MM/dd");
String beforeT = "";
String afterT = "";
if (beforeTime != null && !afterTime.equals("")) {
beforeT = formatX.format(format.parse(beforeTime));
}
if (afterTime != null && !afterTime.equals("")) {
afterT = formatX.format(format.parse(afterTime));
}
// 存储集合
List<RechargeBean> list = new ArrayList<RechargeBean>();
try {
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
HtmlPage page1 = (HtmlPage) client
.getPage("http://XXX/vams/");
HtmlForm form = (HtmlForm) page1.getForms().get(0);
HtmlTextInput username = (HtmlTextInput) form
.getInputByName("login:userName");
HtmlPasswordInput password = (HtmlPasswordInput) form
.getInputByName("login:password");
username.setValueAttribute(userName);
password.setValueAttribute(userPassword);
form.getInputByName("login:j_id_jsp_28762255_4").click();
client.setJavaScriptEnabled(true);
String Recharge = "http://XXX/vams/WebPay/WebPaySearch.faces?showType=2";
HtmlPage Recharge1 = (HtmlPage) client.getPage(Recharge);
HtmlForm rechargeForm = (HtmlForm) Recharge1.getForms().get(0);
// 充值号码
HtmlTextInput payNo = (HtmlTextInput) rechargeForm
.getInputByName("form1:payNo");
payNo.setValueAttribute(payNoValue);
// 充值时间:
HtmlTextInput j_id_jsp_1155368641_9 = (HtmlTextInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_9");
j_id_jsp_1155368641_9.setValueAttribute(beforeT);
HtmlTextInput j_id_jsp_1155368641_11 = (HtmlTextInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_11");
j_id_jsp_1155368641_11.setValueAttribute(afterT);
// 充值金额
HtmlTextInput j_id_jsp_1155368641_13 = (HtmlTextInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_13");
j_id_jsp_1155368641_13.setValueAttribute(rechargeAmount);
// button
HtmlSubmitInput button1 = (HtmlSubmitInput) rechargeForm
.getInputByName("form1:j_id_jsp_1155368641_32");
HtmlPage page12 = (HtmlPage) button1.click();
HtmlForm aa = page12.getForms().get(0);
int divSize = aa.getByXPath("//div[@id='zhu1']").size();
if (divSize > 1) {
HtmlDivision div = (HtmlDivision) aa.getByXPath(
"//div[@id='zhu1']").get(1);
String aad = div.asText();
int pageNumber = (Integer
.parseInt(aad.split("共")[2].split("页")[0].trim()));
Map<String, String[]> map = new HashMap<String, String[]>();
int key = 1;
for (int i = 0; i < pageNumber; i++) {
if (i == 0) {
DomNodeList<HtmlElement> tables = page12
.getElementsByTagName("table");
final HtmlTable table = (HtmlTable) tables.get(tables
.size() - 1);
for (final HtmlTableRow row : table.getBodies().get(0).getRows()) {
String[] alertPring = new String[7];
int d = 0;
for (final HtmlTableCell cell : row.getCells()) {
alertPring[d] = cell.asText();
d++;
}
map.put(key +"", alertPring);
key++;
}
} else {
HtmlPage ahtmpr = div.getHtmlElementsByTagName("a")
.get(3).click();
DomNodeList<HtmlElement> tables2 = ahtmpr
.getElementsByTagName("table");
final HtmlTable table = (HtmlTable) tables2.get(tables2
.size() - 1);
for (final HtmlTableRow row : table.getBodies().get(0)
.getRows()) {
String[] alertPring = new String[7];
int d = 0;
for (final HtmlTableCell cell : row.getCells()) {
alertPring[d] = cell.asText();
d++;
}
map.put(key +"", alertPring);
key++;
}
}
}
Set<String> keyV = map.keySet();
Iterator<String> it2 = keyV.iterator();
while (it2.hasNext()) {
RechargeBean bean = new RechargeBean();
String[] values = map.get(it2.next());
for (int i = 0; i < values.length; i++) {
bean.setId(values[0]);
bean.setDate(values[1]);
bean.setNumber(values[2]);
bean.setAmount(values[3]);
bean.setaType(values[4]);
bean.setsType(values[5]);
bean.setCgType(values[6]);
}
list.add(bean);
}
}
System.out.println("********充值结果查询结束***********");
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
/**
* 返回代理商余额
*/
public static String getBalance() {
String balance = "";
try {
WebClient client = new WebClient(BrowserVersion.INTERNET_EXPLORER_8);
HtmlPage page1 = (HtmlPage) client
.getPage("http://XXX/vams/");
HtmlForm form = (HtmlForm) page1.getForms().get(0);
HtmlTextInput username = (HtmlTextInput) form
.getInputByName("login:userName");
HtmlPasswordInput password = (HtmlPasswordInput) form
.getInputByName("login:password");
username.setValueAttribute(userName);
password.setValueAttribute(userPassword);
form.getInputByName("login:j_id_jsp_28762255_4").click();
client.setJavaScriptEnabled(true);
String Recharge = "http://XXX/vams/WebPay/WebPayRemainSearch.faces";
HtmlPage Recharge1 = (HtmlPage) client.getPage(Recharge);
HtmlForm rechargeForm = (HtmlForm) Recharge1.getForms().get(0);
// button按钮请求
HtmlSubmitInput button1 = (HtmlSubmitInput) rechargeForm
.getInputByName("j_id_jsp_1894475275_1:j_id_jsp_1894475275_32");
HtmlPage page3 = (HtmlPage) button1.click();
DomNodeList<HtmlElement> tables = page3
.getElementsByTagName("table");
final HtmlTable table = (HtmlTable) tables.get(tables.size() - 1);
for (final HtmlTableRow row : table.getBodies().get(0).getRows()) {
int i = 0;
for (final HtmlTableCell cell : row.getCells()) {
if (i == 7) {
HtmlPage page = cell.getHtmlElementsByTagName("a").get(
0).click();
DomNodeList<HtmlElement> pagezhu = (DomNodeList<HtmlElement>) page
.getElementById("zhu1").getElementsByTagName(
"td");
for (int j = 1; j < pagezhu.getLength(); j++) {
balance = pagezhu.get(1).asText();
}
}
i++;
}
}
System.out.println("*************代理商余额查询结束***********");
} catch (Exception e) {
e.printStackTrace();
}
return balance;
}
public static void main(String[] args) throws ParseException {
// 充值结果查询
// 201120619
List<RechargeBean> list = getRechargeList("", "", "", "");
for (int i = 0; i < list.size(); i++) {
RechargeBean bean = list.get(i);
System.out.println(bean.getDate());
}
// getRechargeList("", "", "", "", "");
// 查询余额
// System.out.println(getBalance());
// 进行充值
// System.out.println(recharge("18911019001", ""));
}
}
相关推荐
htmlunit网络爬虫jar包
这个名为“htmlunit爬虫.rar”的压缩包包含了一个基于HTMLUnit的Java爬虫项目,可以用来高效地抓取和分析网络上的数据。 HTMLUnit的核心功能在于其模拟了Web浏览器的行为,包括执行JavaScript、处理cookies、管理...
HtmlUnit是一款功能强大的Java库,它模拟Web浏览器的行为,用于自动化网页交互和数据抓取。这个"HtmlUnit爬虫Demo"可能是一个示例项目,展示了如何利用HtmlUnit库进行网络爬虫开发。以下是对HtmlUnit库及其在爬虫中...
使用htmlnit爬取网页源码并解析,可动态执行js。参数设置
高效的java爬虫,内附... 有htmlunit的各种获取标签的方法。避免了jsoup无法抓取js代码生成的数据内容的弊端。避免了client无法一次性获取大量信息的弊端。有能获取静态页面形成之前的对方数据内容的高手 欢迎借阅指导
在“htmlunit爬虫技术”中,我们将深入探讨如何利用HTMLUnit来实现高效的网络爬虫。 HTMLUnit的核心特性包括: 1. **JavaScript支持**:HTMLUnit能够执行JavaScript代码,这对于许多动态加载内容的现代网站来说至...
这个项目结合了HTMLUnit的功能和Excel的数据处理能力,实现了一个从网页抓取数据并将其存储到Excel电子表格中的解决方案。以下是对这个项目的详细解释: 1. **HTMLUnit简介**: HTMLUnit是一个无头浏览器,它能够...
本项目重点介绍了如何利用htmlunit2.8和jsoup1.7这两个强大的库来实现这一目标。下面我们将深入探讨这两个工具以及它们在数据抓取中的应用。 **htmlunit2.8** HtmlUnit是一个Java库,模仿了一个无头浏览器,能够...
导致htmlunit无法直接感知到需要等待Kissy发起的请求完成,通过等待页面加载解析内容判断处理实现此类页面数据抓取。 基于页面滚动的AJAX请求页面抓取: 诸如淘宝/天猫的商品详情页面会基于页面滚动发起...
HTMLUnit是一个功能强大的Java库,它...通过理解这些依赖包的作用,你可以更好地利用HTMLUnit实现你的目标。在实践中,确保正确地导入这些jar文件,并参考`HtmlunitTest.java`中的示例代码,可以快速上手使用HTMLUnit。
HTMLUnit是一个强大的Java库,它模拟了一个无头Web浏览器,主要用于自动化测试和网页抓取。在版本2.23的zip文件中,我们主要关注HTMLUnit...通过理解和熟练使用这个库,开发者可以构建出精确、灵活的网页数据提取系统。
HTMLUnit是Java编程语言中的一款无头Web浏览器库,它模拟了浏览器的行为,但不涉及图形用户界面。这个工具主要用于自动化测试和网络爬虫,因为它能够解析HTML、执行JavaScript,并与网页上的各种元素进行交互。在...
HTMLUnit是一个Java库,它提供了一个无头浏览器模拟器,用于自动化Web页面的导航和交互。这个库在测试、数据抓取以及不需图形用户界面的场景中非常有用。"htmlUnit所需jar包"的标题表明这是一个包含HTMLUnit运行所需...
1. **导入依赖**:将HTMLUnit及其依赖库添加到项目的类路径中,如果是Maven或Gradle项目,可以通过添加对应的依赖配置来实现。 2. **初始化WebClient**:创建`WebClient`实例,并根据需求设置各种配置,如浏览器版本...
总结起来,这个"htmlunit爬取动态页面包"提供了一整套工具,使得开发者能够编写出能够处理动态内容的Java网络爬虫,通过集成的JavaScript引擎和对HTML的深入解析,实现了高效、全面的数据采集能力。
HTMLUnit是一个强大的无头浏览器库,它允许程序员模拟浏览器行为,...综上所述,HTMLUnit结合Apache POI库可以实现高效且灵活的网页数据抓取和整理,将动态网页内容转化为结构化的Excel表格,方便后续的分析和处理。
这个库对于自动化测试、数据抓取和网页爬虫项目非常有用。标题提到的“htmlunit依赖jar包”是指为了正确运行HTMLUnit,你需要的一系列Java类库。 首先,`htmlunit-2.9.jar`是HTMLUnit的核心库文件,包含了HTMLUnit...
总的来说,HTMLUnit是一个强大而灵活的工具,对于需要在Java环境中进行Web自动化测试和数据抓取的开发者来说,是一个不可多得的选择。通过深入理解和使用HTMLUnit的API,开发者可以构建出高效的测试脚本和数据提取...
通常,它会依赖`rhino-1.x.jar`,这是一个开源的JavaScript引擎,实现了ECMAScript标准。Rhino引擎使得HTMLUnit能够理解和运行JavaScript,这对于模拟浏览器行为至关重要。 5. **其他辅助库**: 还有一些其他辅助...
3. **数据提取**:对于需要解析JavaScript生成内容的网站,HTMLUnit能提供便利的数据提取能力。 三、API使用示例 1. **创建WebClient**: ```java WebClient webClient = new WebClient(); ``` 2. **设置...