如何从网页中抽取需要的信息

marcblue 2010-01-25 03:30:14
想从得到的网页中抽取这个部分的信息,但是不知道如何实现,各位帮帮忙
<table  width="100%" border="0" cellpadding="0" cellspacing="0" class="table01" >
<tr >
<td class="td01" width="18%" nowrap="nowrap" td>注册号:</td>
<td class="td02" width="32%" td>
110112600222478
</td>
<td class="td01" width="18%" td>企业类型:</td>
<td class="td02" width="32%" td>
个体(内地)
</td>
</tr>
<tr >
<!--
<td class="td01" width="18%" td>企业分类:</td>
<td class="td02" width="32%" td>
个体
</td>
-->
<td class="td01" width="18%" td>主体名称:</td>
<td class="td02" width="32%" colspan="3" td>
北京八里桥好运来石材经销部
</td>
</tr>
<tr >
<td class="td01" width="18%" nowrap="nowrap" td>法定代表人/负责人:</td>
<td class="td02" width="32%" td>
李国军
</td>
<td class="td01" width="18%" td>行政区划:</td>
<td class="td02" width="32%" td>
通州区
</td>
</tr>
<tr >
<td class="td01" width="18%" td>成立日期:</td>
<td class="td02" width="32%" td>
2008-06-06
</td>
<td class="td01" width="18%" td>注册资本:</td>
<td class="td02" width="32%" td>

10000



</td>
</tr>
<!-- 如果是企业类型为全民所有或集体所有,则不显示经营期限自和经营期限至 -->

<tr >

<td class="td01" width="18%" td>经营期限自:</td>
<td class="td02" width="32%" td>
2008-06-06 
</td>
<td class="td01" width="18%" td>经营期限至:</td>
<td class="td02" width="32%" td>
2012-06-05
</td>

</tr>

<tr >

<td class="td01" width="18%" td>登记机关:</td>
<td class="td02" width="32%" td>
通州永顺工商所
</td>
<td class="td01" width="18%" td>企业状态:</td>
<td class="td02" width="32%" td>
开业
</td>
</tr>
<tr >

<td class="td01" width="18%" td>地址/住所:</td>
<td class="td02" colspan="3" td>
北京市通州区八里桥农产品中心批发市场石材1号
</td>
</tr>
<tr >

<td class="td01" width="18%" td>经营范围:</td>
<td class="td02" colspan="3" td>

零售石材。

</td>
</tr>
<!--
<tr >

<td class="td01" width="18%" td>许可经营范围:</td>
<td class="td02" colspan="3" > </td>
</tr>
-->
<!--注销吊销日期根据企业状态决定是否显示-->

<!--只针对开业的企业显示年检信息-->

<tr >

<td class="td01" width="18%" td>年检年度:</td>
<td class="td02" width="32%" td>
2009
</td>
<td class="td01" width="18%" td>年检结果:</td>
<td class="td02" width="32%" td>
通过
</td>
</tr>

</table>
...全文
262 23 打赏 收藏 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
marcblue 2010-01-26
  • 打赏
  • 举报
回复
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table01" ></table>
匹配这个标签里的内容得正则怎么写啊
windgh 2010-01-26
  • 打赏
  • 举报
回复
<table.*</table>吧
marcblue 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 20 楼 windgh 的回复:]
匹配到的第几块数据吧,表达式可以被()分成几个部分
如下面的表达式
abc(1)de(2)f
执行后abc1de2f会被match出来,group()/group(0)表示整个,group(1)表示1,group(2)表示2
类推
那个index就是group(index)
[/Quote]
噢明白了,另外要是匹配<table></table>标签里的内容得正则应该怎么写,我写了几个都不正确啊
windgh 2010-01-26
  • 打赏
  • 举报
回复
匹配到的第几块数据吧,表达式可以被()分成几个部分
如下面的表达式
abc(1)de(2)f
执行后abc1de2f会被match出来,group()/group(0)表示整个,group(1)表示1,group(2)表示2
类推
那个index就是group(index)
marcblue 2010-01-26
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 zhangkai08111 的回复:]
1.使用 org.apache.oro.text.regex
Java code/**
* 按正则和组下标匹配数据
*
*@param content
*@param regx
*@param index
*@return
*@throws MalformedPatternException*/publicstatic String getMatchString(String content, String regx,int index)throws MalformedPatternException {
PatternCompiler orocom=new Perl5Compiler();
Pattern pattern1= orocom.compile(regx);
PatternMatcher matcher=new Perl5Matcher();
String sentence="";if (matcher.contains(content, pattern1)) {
MatchResult result= matcher.getMatch();
sentence= result.group(index);
}return sentence;
}

Java code
用法:getMatchString(html内容,"<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table01" >(*.?)</table>", int index)
2.使用html parser。。
3.xml
[/Quote]
public static String getMatchString(String content, String regx, int index) throws MalformedPatternException {}
int index代表什么?
crazylaa 2010-01-25
  • 打赏
  • 举报
回复
正则。或html parser
windgh 2010-01-25
  • 打赏
  • 举报
回复
<td[^>]*>企业类型[^<]*</td><td[^>]*>([^<]*)</td>
这个正则表达式可以取企业类型的值,用java的matcher.group(1)可以取到
其余的类型类推
windgh 2010-01-25
  • 打赏
  • 举报
回复
用xml解析要小心格式问题
html容错性是很强的,哪里少个闭标签,弄不好你就得痛不欲生,嘿嘿
用正则会好点
kernll 2010-01-25
  • 打赏
  • 举报
回复
对就是要用xml解析。要不就太麻烦了
  • 打赏
  • 举报
回复
1.使用 org.apache.oro.text.regex


/**
* 按正则和组下标匹配数据
*
* @param content
* @param regx
* @param index
* @return
* @throws MalformedPatternException
*/
public static String getMatchString(String content, String regx, int index) throws MalformedPatternException {
PatternCompiler orocom = new Perl5Compiler();
Pattern pattern1 = orocom.compile(regx);
PatternMatcher matcher = new Perl5Matcher();
String sentence = "";
if (matcher.contains(content, pattern1)) {
MatchResult result = matcher.getMatch();
sentence = result.group(index);
}
return sentence;
}




用法:getMatchString(html内容, "<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table01" >
(*.?)</table>", int index)

2.使用html parser。。
3.xml
  • 打赏
  • 举报
回复
给你找找以前的爬虫。。。
marcblue 2010-01-25
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 phyerbarte 的回复:]
估计就是个爬虫啊什么的,分析别人网站里的数据,不能够读别人数据库,只能从别人的网页里抓东西分析,然后插自己库。。。
这种东西,一般貌似就是正则,要么就是当XML解析吧。
[/Quote]
恩对就是这个意思,我现在就想把得到的html先变成xml,然后再用正则去掉没用的东西
luanhongyan 2010-01-25
  • 打赏
  • 举报
回复
网页外挂!
phyerbarte 2010-01-25
  • 打赏
  • 举报
回复
估计就是个爬虫啊什么的,分析别人网站里的数据,不能够读别人数据库,只能从别人的网页里抓东西分析,然后插自己库。。。
这种东西,一般貌似就是正则,要么就是当XML解析吧。
kkkkkkkkkk21312 2010-01-25
  • 打赏
  • 举报
回复
继续顶吧,希望楼主说明点,到底要怎样
小一郎 2010-01-25
  • 打赏
  • 举报
回复
用正则表达式或者直接用字符串匹配
pwl2014 2010-01-25
  • 打赏
  • 举报
回复
使用 html parser
霜之哀伤 2010-01-25
  • 打赏
  • 举报
回复
后台?为什么不直接读数据库

如果html比较标准的话,直接当xml读就行了。
marcblue 2010-01-25
  • 打赏
  • 举报
回复
恩这个是要在后台完成的,应该是要用正则表达式从里面抽取出企业名称和企业类型什么的,但是我对正则表达式不太精通。。。
kkkkkkkkkk21312 2010-01-25
  • 打赏
  • 举报
回复
-----加上point.js脚本
<script language="JavaScript" src="../../jscss/point.js"></script>
-----调用js脚本中的方法
<input type="button" name="button" value="摘取" id="Submit" onClick="doPrint();" />
------添加你摘取的内容在<div>中
<div id="doctitle">
你的内容
</div>

-----------point.js内容

function doPrint() {
var newWin = window.open('about:blank','1111','height=350,width=800,top=230,left=280,toolbar=no,menubar=yes,scrollbars=yes, resizable=no,location=no, status=no');
var titleHTML = document.getElementById("doctitle").innerHTML;
newWin.document.write(titleHTML);
newWin.document.location.reload();
//newWin.portrait = false ;
//newWin.leftMargin = 1.0 ;
//newWin.topMargin = 1.0 ;
//newWin.rightMargin = 1.0 ;
//newWin.bottomMargin = 1.0 ;
//newWin.print();
//newWin.close();
}
-------------
通过测试完全可用
加载更多回复(3)

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧