社区
Java SE
帖子详情
急!HtmlParser提取文本的问题,求教
sjc12
2010-05-12 09:28:34
我用HtmlParser在《开发自己的搜索引擎》基础上想提取
http://product.pconline.com.cn/notebook/lenovo/261638_detail.html 里的参数,把他们存到txt里,但那个类始终有问题,不知有没有牛人能够帮个忙?
...全文
218
4
打赏
收藏
急!HtmlParser提取文本的问题,求教
我用HtmlParser在《开发自己的搜索引擎》基础上想提取 http://product.pconline.com.cn/notebook/lenovo/261638_detail.html 里的参数,把他们存到txt里,但那个类始终有问题,不知有没有牛人能够帮个忙?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
SelfMedicated
2012-03-13
打赏
举报
回复
楼主,http://blog.sina.com.cn/s/blog_3c6ecea90100iub1.html,希望对你有帮助
sjc12
2010-05-12
打赏
举报
回复
希望能帮我弄弄,比较急,我也是初学者,谢谢了
sjc12
2010-05-12
打赏
举报
回复
不好意思 就一个方法
public void extract() {
BufferedWriter bw = null;
//创建属性过滤器
NodeFilter attributes_filter = new AndFilter(new TagNameFilter("td"),
new HasAttributeFilter("WIDTH", "16%"));
//创建标题过滤器
NodeFilter title_filter = new AndFilter(new TagNameFilter("span"),
new HasAttributeFilter("class", "mark")
);
//提取标题信息
try {
//Parser根据过滤器返回所有满足过滤条件的节点
NodeList title_nodes = this.getParser().parse(title_filter);
//遍历所有节点
for (int i = 0; i < title_nodes.size(); i++) {
TableColumn node = (TableColumn) title_nodes.elementAt(i);
//用空格分割节点内胡html文本
String[] names = node.getChildrenHTML().split(" ");
StringBuffer title = new StringBuffer();
//创建要生成的文本文件名
for (int k = 0; k < names.length; k++) {
title.append(names[k]).append("-");
}
title.append((new Date()).getTime());
//创建要生成的文件
bw = new BufferedWriter(new FileWriter(new File(this
.getOutputPath()
+ title + ".txt")));
//获取当前提取页的完整URL地址
int startPos = getInuputFilePath().indexOf("mirror") + 6;
String url_seg = getInuputFilePath().substring(startPos);
url_seg = url_seg.replaceAll("\\\\", "/");
String url = "http:/" + url_seg;
System.out.println(url);
//写入当前提取页的完整URL地址
bw.write(url + NEWLINE);
bw.write(names[0] + NEWLINE);
bw.write(names[1] + NEWLINE);
}
} catch (Exception e) {
e.printStackTrace();
}
//重置Parser
this.getParser().reset();
try {
//Parser根据过滤器返回所有满足过滤条件的节点
NodeList attributes_nodes = this.getParser().parse(attributes_filter);
for (int i = 0; i < attributes_nodes.size(); i++) {
//Parser根据过滤器返回所有满足过滤条件的节点
TableColumn node = (TableColumn) attributes_nodes.elementAt(i);
String text = node.getChildrenHTML();
//提取属性名信息
String result = getProp(
"<TD width=\"16%\" class=\"#FCFCFC\">(.*)</TD>",
node.toHtml(), 1);
//属性里面包含有link标签的情况
if (result.indexOf("<") != -1)
result = getProp(
"<TD CLASS=btd WIDTH=198 BGCOLOR=\"#FCFCFC\"(.*)>(.*)</a></B></TD>",
node.toHtml(), 2);
//提取属性值信息
TableColumn nodeExt = (TableColumn) node.getNextSibling()
.getNextSibling();
bw.write(StringUtils.trim(result) + ":"
+ StringUtils.trim(nodeExt.getChildrenHTML()));
bw.newLine();
continue;
}
} catch (Exception e) {
e.printStackTrace();
}
amdgaming
2010-05-12
打赏
举报
回复
你说的清楚点啊? 比如把你类 发出来
你这样没头没脑 谁 能回答出你的问题啊
java html
提取
纯
文本
_利用
htmlparser
提取
网页纯
文本
该博客展示了使用Java代码利用
htmlparser
库
提取
网页纯
文本
的示例。代码通过建立网络连接获取网页内容,然后遍历节点
提取
文本
。还包含了对特定标签(如table)的处理方法,最终实现从网页中
提取
纯
文本
的功能。
java
htmlparser
使用教程_java使用
htmlparser
提取
网页纯
文本
例子
该博客主要展示了Java使用
HtmlParser
库的示例代码。通过创建Parser对象,利用NodeFilter筛选节点,实现从网页中
提取
纯
文本
的功能。代码包含了网络连接获取网页内容、遍历节点
提取
文本
等操作,为使用
HtmlParser
提供了实践参考。
使用
HtmlParser
提取
HTML
文本
块
本文介绍了使用Java版
HtmlParser
进行网页预处理的经验,探讨了如何根据网页类型(主题型与hub型)制定
提取
策略,包括
提取
标题、关键词、摘要及正文内容的方法。
爬虫实战:基于
HtmlParser
实现网页链接的
提取
本文介绍如何使用
HtmlParser
库
提取
网页中的链接。通过构建过滤器,可以高效地筛选出所需的链接。
htmlparser
获取html,根据
htmlparser
写的一个
提取
页面纯
文本
的C#程序
这是一个C#程序,用于从网页中
提取
文本
内容并处理可能出现的乱码
问题
。程序使用Winista.Text.
HtmlParser
库解析HTML,通过检查charset来确定正确的编码,并去除JavaScript和样式。最终,它将
提取
的
文本
进行修剪和展示。
Java SE
62,621
社区成员
307,251
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章