- 浏览: 2564890 次
- 性别:
- 来自: 成都
-
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
HTML解析htmlparser
htmlparser
首页:http://sourceforge.net/projects/htmlparser/
下载:http://sourceforge.net/project/showfiles.php?group_id=24399
文件:HTMLParser-2.0-SNAPSHOT-bin.zip
cpdetector
首页:http://cpdetector.sourceforge.net/
下载:http://sourceforge.net/project/showfiles.php?group_id=114421
文件:cpdetector_eclipse_project_1.0.7.zip
解开压缩后,运行ANT打包命令,build.xml有些地方需要稍微根据具体情况调整一下
ant jar.htmlentitydecoder
得到JAR包
cpdetector_1.0.7.jar
HTML工具类函数一:自动探测URL的HTML内容的编码
/**
* 自动探测页面的编码
*
* @param url
* @return
* @throws MalformedURLException
*/
public static String autoDetectCharset(String url) {
URL source = null;
try {
source = new URL(url);
} catch (MalformedURLException e) {
log.error(e);
}
CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
detector.add(new ParsingDetector(false));
detector.add(JChardetFacade.getInstance());
detector.add(ASCIIDetector.getInstance());
detector.add(UnicodeDetector.getInstance());
Charset charset = null;
try {
charset = detector.detectCodepage(source);
} catch (IOException e) {
log.error(e);
}
if (charset == null) {
charset = Charset.defaultCharset();
}
return charset.name();
}
HTML工具类函数二:读取URL中的HTML文本
/**
* 读取文件HTML内容
*
* @param url
* @param charset
* @return
* @throws IOException
*/
public static String readURL(String url, String charset) {
/* StringBuffer的缓冲区大小 */
int TRANSFER_SIZE = 4096;
/* 当前平台的行分隔符 */
String lineSep = System.getProperty("line.separator");
String content = "";
URL source = null;
try {
source = new URL(url);
} catch (MalformedURLException e) {
log.error(e);
}
InputStream in = null;
try {
in = source.openStream();
} catch (IOException e) {
log.error(e);
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(in, charset));
} catch (UnsupportedEncodingException e) {
log.error(e);
}
String line = new String();
StringBuffer temp = new StringBuffer(TRANSFER_SIZE);
try {
while ((line = reader.readLine()) != null) {
temp.append(line);
temp.append(lineSep);
}
in.close();
reader.close();
} catch (IOException e) {
log.error(e);
}
content = temp.toString();
return content;
}
HTML工具类函数三:解析HTML得到其中的所有TAG
public static NodeList getFormNodeList(String url) {
Parser parser = Parser.createParser(readURL(url),
autoDetectCharset(url));
PrototypicalNodeFactory factory = new PrototypicalNodeFactory();
factory.registerTag(new ScclSelectBizCodesTag());
factory.registerTag(new InputTag());
factory.registerTag(new TextareaTag());
parser.setNodeFactory(factory);
NodeFilter formFilter = new PostFormFilter();
NodeList nodeList = null;
try {
nodeList = parser.extractAllNodesThatMatch(formFilter);
} catch (ParserException e) {
log.error(e);
}
return nodeList;
}
HTML工具类函数四:解析TAG中的属性,生成所有的PageField的POJO
public static List<PageField> getPageFields(String url) {
List<PageField> list = null;
NodeList nodeList = getFormNodeList(url);
if (nodeList != null && nodeList.size() > 0) {
// nodeList不为空,开始构建
list = new ArrayList<PageField>(nodeList.size());
for (int i = 0; i < nodeList.size(); i++) {
TagNode node = (TagNode) nodeList.elementAt(i);
if (node instanceof InputTag) {
InputTag input = (InputTag) node;
PageField t = new PageField(input.getAttribute("name"),
PageField.TAG_TYPE_INPUT, input
.getAttribute("type"));
list.add(t);
} else if (node instanceof ScclSelectBizCodesTag) {
ScclSelectBizCodesTag scclSelectBizCodesTag = (ScclSelectBizCodesTag) node;
PageField t = new PageField(scclSelectBizCodesTag
.getAttribute("id"),
PageField.TAG_TYPE_SELECT, null);
list.add(t);
} else if (node instanceof TextareaTag) {
TextareaTag textArea = (TextareaTag) node;
PageField t = new PageField(textArea.getAttribute("name"),PageField.TAG_TYPE_TEXTAREA,null);
list.add(t);
}
}
}
return list;
}
扩展自定义标签<sccl:selectBizCodes>
public class ScclSelectBizCodesTag extends TagNode {
private static final long serialVersionUID = -6352090777443844707L;
private static final String[] ids = new String[] { "sccl:selectBizCodes" };
public String[] getIds() {
return (ids);
}
public String[] getEnders() {
return (ids);
}
public String getCategory(){
return super.getAttribute("category");
}
public String getId(){
return super.getAttribute("id");
}
public String getSelected(){
return super.getAttribute("selected");
}
}
用FILTER方式过滤访问TAG
public class PostFormFilter implements NodeFilter {
private static final long serialVersionUID = 8162322553987269165L;
public boolean accept(Node node) {
if (node instanceof InputTag) {
return true;
}
if (node instanceof ScclSelectBizCodesTag) {
return true;
}
if (node instanceof TextareaTag) {
return true;
}
return false;
}
}
测试
public static void main(String[] args)
throws org.htmlparser.util.ParserException, IOException {
String url = "file:///E:\\work\\html\\editOrder.jsp";
List<PageField> list = getPageFields(url);
list.get(0);
}
以上代码可以解析<input> <select> 自定义类型
<sccl:selectBizCodes category="worksheet" id="worksheetCode" selected="cl" onChange="go();" html="style='test';"/>
问题一
拷贝cpdetector_1.0.7.jar到项目中后
同时也要拷贝ext下面的chardet.jar到lib下面,不然在调用
detector.add(JChardetFacade.getInstance());时要报错,找不到类
nsICharsetDetectionObserver
问题二
拷贝htmlparser相关包如下:
htmlparser.jar
htmllexer.jar
htmlparser
首页:http://sourceforge.net/projects/htmlparser/
下载:http://sourceforge.net/project/showfiles.php?group_id=24399
文件:HTMLParser-2.0-SNAPSHOT-bin.zip
cpdetector
首页:http://cpdetector.sourceforge.net/
下载:http://sourceforge.net/project/showfiles.php?group_id=114421
文件:cpdetector_eclipse_project_1.0.7.zip
解开压缩后,运行ANT打包命令,build.xml有些地方需要稍微根据具体情况调整一下
ant jar.htmlentitydecoder
得到JAR包
cpdetector_1.0.7.jar
HTML工具类函数一:自动探测URL的HTML内容的编码
/**
* 自动探测页面的编码
*
* @param url
* @return
* @throws MalformedURLException
*/
public static String autoDetectCharset(String url) {
URL source = null;
try {
source = new URL(url);
} catch (MalformedURLException e) {
log.error(e);
}
CodepageDetectorProxy detector = CodepageDetectorProxy.getInstance();
detector.add(new ParsingDetector(false));
detector.add(JChardetFacade.getInstance());
detector.add(ASCIIDetector.getInstance());
detector.add(UnicodeDetector.getInstance());
Charset charset = null;
try {
charset = detector.detectCodepage(source);
} catch (IOException e) {
log.error(e);
}
if (charset == null) {
charset = Charset.defaultCharset();
}
return charset.name();
}
HTML工具类函数二:读取URL中的HTML文本
/**
* 读取文件HTML内容
*
* @param url
* @param charset
* @return
* @throws IOException
*/
public static String readURL(String url, String charset) {
/* StringBuffer的缓冲区大小 */
int TRANSFER_SIZE = 4096;
/* 当前平台的行分隔符 */
String lineSep = System.getProperty("line.separator");
String content = "";
URL source = null;
try {
source = new URL(url);
} catch (MalformedURLException e) {
log.error(e);
}
InputStream in = null;
try {
in = source.openStream();
} catch (IOException e) {
log.error(e);
}
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(in, charset));
} catch (UnsupportedEncodingException e) {
log.error(e);
}
String line = new String();
StringBuffer temp = new StringBuffer(TRANSFER_SIZE);
try {
while ((line = reader.readLine()) != null) {
temp.append(line);
temp.append(lineSep);
}
in.close();
reader.close();
} catch (IOException e) {
log.error(e);
}
content = temp.toString();
return content;
}
HTML工具类函数三:解析HTML得到其中的所有TAG
public static NodeList getFormNodeList(String url) {
Parser parser = Parser.createParser(readURL(url),
autoDetectCharset(url));
PrototypicalNodeFactory factory = new PrototypicalNodeFactory();
factory.registerTag(new ScclSelectBizCodesTag());
factory.registerTag(new InputTag());
factory.registerTag(new TextareaTag());
parser.setNodeFactory(factory);
NodeFilter formFilter = new PostFormFilter();
NodeList nodeList = null;
try {
nodeList = parser.extractAllNodesThatMatch(formFilter);
} catch (ParserException e) {
log.error(e);
}
return nodeList;
}
HTML工具类函数四:解析TAG中的属性,生成所有的PageField的POJO
public static List<PageField> getPageFields(String url) {
List<PageField> list = null;
NodeList nodeList = getFormNodeList(url);
if (nodeList != null && nodeList.size() > 0) {
// nodeList不为空,开始构建
list = new ArrayList<PageField>(nodeList.size());
for (int i = 0; i < nodeList.size(); i++) {
TagNode node = (TagNode) nodeList.elementAt(i);
if (node instanceof InputTag) {
InputTag input = (InputTag) node;
PageField t = new PageField(input.getAttribute("name"),
PageField.TAG_TYPE_INPUT, input
.getAttribute("type"));
list.add(t);
} else if (node instanceof ScclSelectBizCodesTag) {
ScclSelectBizCodesTag scclSelectBizCodesTag = (ScclSelectBizCodesTag) node;
PageField t = new PageField(scclSelectBizCodesTag
.getAttribute("id"),
PageField.TAG_TYPE_SELECT, null);
list.add(t);
} else if (node instanceof TextareaTag) {
TextareaTag textArea = (TextareaTag) node;
PageField t = new PageField(textArea.getAttribute("name"),PageField.TAG_TYPE_TEXTAREA,null);
list.add(t);
}
}
}
return list;
}
扩展自定义标签<sccl:selectBizCodes>
public class ScclSelectBizCodesTag extends TagNode {
private static final long serialVersionUID = -6352090777443844707L;
private static final String[] ids = new String[] { "sccl:selectBizCodes" };
public String[] getIds() {
return (ids);
}
public String[] getEnders() {
return (ids);
}
public String getCategory(){
return super.getAttribute("category");
}
public String getId(){
return super.getAttribute("id");
}
public String getSelected(){
return super.getAttribute("selected");
}
}
用FILTER方式过滤访问TAG
public class PostFormFilter implements NodeFilter {
private static final long serialVersionUID = 8162322553987269165L;
public boolean accept(Node node) {
if (node instanceof InputTag) {
return true;
}
if (node instanceof ScclSelectBizCodesTag) {
return true;
}
if (node instanceof TextareaTag) {
return true;
}
return false;
}
}
测试
public static void main(String[] args)
throws org.htmlparser.util.ParserException, IOException {
String url = "file:///E:\\work\\html\\editOrder.jsp";
List<PageField> list = getPageFields(url);
list.get(0);
}
以上代码可以解析<input> <select> 自定义类型
<sccl:selectBizCodes category="worksheet" id="worksheetCode" selected="cl" onChange="go();" html="style='test';"/>
问题一
拷贝cpdetector_1.0.7.jar到项目中后
同时也要拷贝ext下面的chardet.jar到lib下面,不然在调用
detector.add(JChardetFacade.getInstance());时要报错,找不到类
nsICharsetDetectionObserver
问题二
拷贝htmlparser相关包如下:
htmlparser.jar
htmllexer.jar
发表评论
-
Update Site will come soon
2021-06-02 04:10 1688I am still keep notes my tech n ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 437Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 447Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 383Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 469VPN Server 2020(2)Docker on Cen ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 370Nginx Deal with OPTIONS in HTTP ... -
PDF to HTML 2020(1)pdftohtml Linux tool or PDFBox
2020-01-29 07:37 434PDF to HTML 2020(1)pdftohtml Li ... -
Elasticsearch Cluster 2019(2)Kibana Issue or Upgrade
2020-01-12 03:25 738Elasticsearch Cluster 2019(2)Ki ... -
Spark Streaming 2020(1)Investigation
2020-01-08 07:19 305Spark Streaming 2020(1)Investig ... -
Hadoop Docker 2019 Version 3.2.1
2019-12-10 07:39 308Hadoop Docker 2019 Version 3.2. ... -
MongoDB 2019(3)Security and Auth
2019-11-16 06:48 251MongoDB 2019(3)Security and Aut ... -
MongoDB 2019(1)Install 4.2.1 Single and Cluster
2019-11-11 05:07 301MongoDB 2019(1) Follow this ht ... -
Monitor Tool 2019(1)Monit Installation and Usage
2019-10-17 08:22 335Monitor Tool 2019(1)Monit Insta ... -
Ansible 2019(1)Introduction and Installation on Ubuntu and CentOS
2019-10-12 06:15 324Ansible 2019(1)Introduction and ... -
Timezone and Time on All Servers and Docker Containers
2019-10-10 11:18 346Timezone and Time on All Server ... -
Kafka Cluster 2019(6) 3 Nodes Cluster on CentOS7
2019-10-05 23:28 297Kafka Cluster 2019(6) 3 Nodes C ... -
K8S Helm(1)Understand YAML and Kubectl Pod and Deployment
2019-10-01 01:21 340K8S Helm(1)Understand YAML and ... -
Rancher and k8s 2019(5)Private Registry
2019-09-27 03:25 378Rancher and k8s 2019(5)Private ... -
Jenkins 2019 Cluster(1)Version 2.194
2019-09-12 02:53 459Jenkins 2019 Cluster(1)Version ... -
Redis Cluster 2019(3)Redis Cluster on CentOS
2019-08-17 04:07 382Redis Cluster 2019(3)Redis Clus ...
相关推荐
本文将深入探讨一个名为"ftp-client"的前端开源库,它是Node.js FTP模块的一个包装器,专为前端开发设计,帮助开发者实现FTP(File Transfer Protocol)功能。 FTP是一种用于在网络上进行文件传输的标准协议,它...
在这个基于 lwip 的 FTP 客户端代码实例中,我们主要关注如何在 ucOS 操作系统环境下,利用 lwip(Lightweight IP)库来实现 FTP 客户端的功能,以便从远程服务器下载更新程序到嵌入式设备的闪存中。 lwip 是一个...
Java FTP服务器可能使用了Apache Commons Net库或其他开源库来实现,这些库提供了处理FTP命令、管理用户权限和数据传输等功能。 在Java中实现FTP,主要涉及以下几个关键点: 1. **建立连接**:使用`Socket`类创建...
**FileZilla FTP Client**是一款深受用户喜爱的开源FTP客户端软件,它以其高效、稳定和易用性在众多FTP工具中脱颖而出。作为一个免费且纯绿色的解决方案,FileZilla不仅避免了广告干扰,而且无需安装即可使用,为...
FileZilla FTP Client是该协议的实现之一,提供了一种简单易用的图形用户界面,使得非技术用户也能轻松地在互联网上上传和下载文件。 首先,让我们深入了解一下FTP的基本工作原理。FTP通过TCP/IP协议在网络中建立...
开源库的包名是这个org.apache.commons.net.ftp.FTPClient;是属于局域网的ftp上传,要有ip、端口、用户名以及密码。我根据网上的下载demo,自已研究了一番,又封装了一个类自已使用。欢迎访问博客:...
FileZilla FTP Client是一款广泛应用的开源FTP客户端,它在IT领域扮演着重要的角色,尤其对于文件的上传和下载测试。FTP(File Transfer Protocol)是一种网络协议,用于在互联网上进行文件传输。FileZilla因其易用...
"Yet Another FTP Client",简称Yafc,是一款基于开源协议的控制台界面FTP客户端工具。这个项目旨在提供一个高效、功能丰富的FTP文件传输解决方案,尤其适用于那些喜欢通过命令行界面操作的用户。Yafc的设计理念是...
一个简单的FTP客户端。
FileZilla FTP Client是一款广泛应用的开源FTP客户端,它支持FTP(文件传输协议)以及SFTP(安全文件传输协议)。这款工具因其高效、可靠且用户友好的特性而在IT专业人士和普通用户中广受好评。 FTP是互联网上最早...
`ftp_client_proj`可能是这个FTP客户端项目的源代码文件夹,里面可能包含以下组件: 1. `main.c`:主程序,初始化FTP会话,处理用户输入,调用其他函数执行FTP命令。 2. `ftp_commands.c`:实现各种FTP命令的函数。 ...
FileZilla FTP Client是一款流行的开源FTP(文件传输协议)客户端,广泛用于在互联网上上传、下载文件和管理远程服务器上的文件。它支持多种协议,包括FTP、FTPS(FTP over SSL/TLS)以及SFTP(SSH文件传输协议)。...
在 lwftp-master 压缩包中,我们可以找到这个基于LWIP raw API的FTP客户端实现,包括源码文件、配置文件和可能的示例用法。解压后,可以查阅代码了解如何将LWIP的底层网络功能与FTP协议结合起来。通过阅读和理解这些...
压缩包中的"FileZilla-3.1.1.1_ftp_client_ipv6_enable"文件可能是安装程序或更新补丁,用于启用或优化IPv6功能。下载并安装这个文件后,用户将能够充分利用FileZilla对IPv6的支持,享受高效、安全的FTP文件传输体验...
FileZilla FTP Client是一款强大的、开源的FTP(文件传输协议)客户端软件,广泛应用于个人用户和企业环境中,用于上传、下载以及管理远程服务器上的文件。它支持FTP、FTPS(安全文件传输协议)以及SFTP(SSH文件...
FileZilla FTP Client是一款广泛应用的开源FTP客户端,它提供了高效、安全的文件传输功能,适用于个人用户和专业团队。这款工具以其易用性、稳定性和丰富的特性而受到广泛的赞誉。 ### 1. 简介 FileZilla FTP ...
FileZilla FTP Client是一款广泛应用的开源FTP(文件传输协议)客户端,支持FTP、FTPS(FTP over SSL/TLS)和SFTP(SSH文件传输协议),适用于Windows、Linux和Mac OS等多平台。作为一款功能丰富的专业级FTP工具,它...