标题:关于解析html的问题
只看楼主
history_sky
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2005-12-14
 问题点数:0 回复次数:8 
关于解析html的问题

各位老大:
我现在希望用C写一个解析html的程序,我解析的是http传过来的html,如下所示:
<html><head><style type=text/css>td {font-size:12px;text-align:center;line-height:normal;}</style><TITLE>Phone V1.43.021 </TITLE><script language=javascript>function selchange_iptype(){var ival;ival = document.forms[0].iptype.value;switch(ival){case "0":document.forms[0].pppid.disabled = 1;document.forms[0].ppppin.disabled = 1;document.forms[0].ip.disabled = 0;document.forms[0].subnetmask.disabled = 0;document.forms[0].router.disabled = 0;document.forms[0].dns.disabled = 0;document.forms[0].dns2.disabled = 0;break;case "1":document.forms[0].pppid.disabled = 1;document.forms[0].ppppin.disabled = 1;document.forms[0].ip.disabled = 1;document.forms[0].subnetmask.disabled = 1;document.forms[0].router.disabled = 1;document.forms[0].dns.disabled = 1;document.forms[0].dns2.disabled = 1;break;case "2":document.forms[0].pppid.disabled = 0;document.forms[0].ppppin.disabled = 0;document.forms[0].ip.disabled = 1;document.forms[0].subnetmask.disabled = 1;document.forms[0].router.disabled = 1;document.forms[0].dns.disabled = 0;document.forms[0].dns2.disabled = 0;break;case "3":document.forms[0].pppid.disabled = 0;document.forms[0].ppppin.disabled = 0;document.forms[0].ip.disabled = 1;document.forms[0].subnetmask.disabled = 1;document.forms[0].router.disabled = 1;document.forms[0].dns.disabled = 1;document.forms[0].dns2.disabled = 1;break;default:break;}}</script></head><body bgcolor=#E7EBFF onLoad=selchange_iptype()><form method=POST action=/b><div align=center><center><table border=1 cellspacing=0 cellpadding=0 bordercolor=#CEDBFF><tr><td colspan=6 bgcolor=#CEDBFF><FONT size=4>........</FONT></td></tr><tr><td>ip........</td><td><SELECT name=iptype onChange=selchange_iptype() size=1><OPTION value=0 SELECTED>....ip</OPTION><OPTION value=1 >dhcp</OPTION><OPTION value=2 >pppoe</OPTION><OPTION value=3 >modem</OPTION></SELECT></td><td>ppp....</td><td><INPUT name=pppid value="" size=24 maxlength=40></td><td>ppp....</td><td><INPUT name=ppppin value="" size=24 maxlength=24></td></tr><tr><td>....ip....</td><td><INPUT name=ip value=192.168.1.27 size=16 maxlength=15></td><td>........</td><td><INPUT name=subnetmask value=255.255.255.0 size=16 maxlength=15></td><td>....ip....</td><td><INPUT name=router value=192.168.1.1 size=16 maxlength=15></td></tr><tr><td>dns ip....</td><td><INPUT name=dns value=221.4.66.66 size=16 maxlength=15></td><td>....dns ip....</td><td><INPUT name=dns2 value=210.51.176.71 size=16 maxlength=15></td><td>mac....</td><td><INPUT name=mac value=00-09-45-32-56-a8 size=16 maxlength=17></td></tr><tr><td colspan=6 bgcolor=#CEDBFF><FONT size=4>........</FONT></td></tr><tr><td>........1</td><td><SELECT name=codec1 size=1><OPTION value=0 >g729</OPTION><OPTION value=1 SELECTED>g7231</OPTION><OPTION value=2 >g711u</OPTION><OPTION value=3 >g711a</OPTION><OPTION value=4 >gsm</OPTION><OPTION value=5 >iLBC</OPTION><OPTION value=6 >null</OPTION></SELECT></td><td>........2</td><td><SELECT name=codec2 size=1><OPTION value=0 SELECTED>g729</OPTION><OPTION value=1 >g7231</OPTION><OPTION value=2 >g711u</OPTION><OPTION value=3 >g711a</OPTION><OPTION value=4 >gsm</OPTION><OPTION value=5 >iLBC</OPTION><OPTION value=6 >null</OPTION></SELECT></td><td>........3</td><td><SELECT name=codec3 size=1><OPTION value=0 >g729</OPTION><OPTION value=1 >g7231</OPTION><OPTION value=2 SELECTED>g711u</OPTION><OPTION value=3 >g711a</OPTION><OPTION value=4 >gsm</OPTION><OPTION value=5 >iLBC</OPTION><OPTION value=6 >null</OPTION></SELECT></td></tr><tr><td>........4</td><td><SELECT name=codec4 size=1><OPTION value=0 >g729</OPTION><OPTION value=1 >g7231</OPTION><OPTION value=2 >g711u</OPTION><OPTION value=3 SELECTED>g711a</OPTION><OPTION value=4 >gsm</OPTION><OPTION value=5 >iLBC</OPTION><OPTION value=6 >null</OPTION></SELECT></td><td>........5</td><td><SELECT name=codec5 size=1><OPTION value=0 >g729</OPTION><OPTION value=1 >g7231</OPTION><OPTION value=2 >g711u</OPTION><OPTION value=3 >g711a</OPTION><OPTION value=4 SELECTED>gsm</OPTION><OPTION value=5 >iLBC</OPTION><OPTION value=6 >null</OPTION></SELECT></td><td>........6</td><td><SELECT name=codec6 size=1><OPTION value=0 >g729</OPTION><OPTION value=1 >g7231</OPTION><OPTION value=2 >g711u</OPTION><OPTION value=3 >g711a</OPTION><OPTION value=4 >gsm</OPTION><OPTION value=5 >iLBC</OPTION><OPTION value=6 SELECTED>null</OPTION></SELECT></td></tr><tr><td>vad</td><td><INPUT name=vad type=checkbox></td><td>agc</td><td><INPUT name=agc type=checkbox></td><td><SELECT name=dialplan onChange=selchange_dialplan() size=1><OPTION value=0 SELECTED>......</OPTION><OPTION value=1 >....</OPTION><OPTION value=2 >dialnum</OPTION><OPTION value=3 >prefix</OPTION><OPTION value=4 >hotline</OPTION></SELECT></td><td>........</td><td><INPUT name=dialnumber value="" size=16 maxlength=16></td><td>....</td><td><INPUT name=dddcode value="" size=5 maxlength=4></td></tr><tr><td>........</td><td><INPUT name=iddcode value="" size=5 maxlength=4></td><td>............</td><td><INPUT name=iddprefix value="00" size=5 maxlength=4></td><td>............</td><td><INPUT name=dddprefix value="" size=5 maxlength=3></td></tr><tr><td>........</td><td><SELECT name=innerline onChange=selchange_innerline() size=1><OPTION value=0 SELECTED>......</OPTION><OPTION value=1 >....</OPTION><OPTION value=2 >omit prefix</OPTION></SELECT></td><td>........</td><td><INPUT name=innerlineprefix value="0" size=5 maxlength=2></td><td>........</td><td><INPUT name=callwaiting type=checkbox></td></tr><tr><td>............</td> <td><INPUT name=fwdnumber value="" size=16 maxlength=24></td><td>........</td><td><INPUT name=fwdpoweroff type=checkbox></td><td>..........</td><td><INPUT name=fwdnoanswer type=checkbox></td></tr><tr><td>........</td><td><INPUT name=fwdalways type=checkbox></td><td>........</td><td><INPUT name=fwdbusy type=checkbox></td><td>........</td><td><INPUT name=answer value=30 size=5 maxlength=2></td></tr><tr><td>............</td><td><INPUT name=digitmap type=checkbox></td></tr><tr><td colspan=24 bgcolor=#CEDBFF ><FONT size=4>H323........</FONT></td></tr><tr><td>............</td><td><INPUT name=service CHECKED type=checkbox></td><td>........</td><td><SELECT name=servicetype size=1><OPTION value=0 >common</OPTION><OPTION value=1 >huawei</OPTION><OPTION value=2 >zte</OPTION><OPTION value=3 >harbour</OPTION><OPTION value=4 >utstarcom</OPTION><OPTION value=5 >soyo</OPTION><OPTION value=6 >etalk</OPTION><OPTION value=7 >dda</OPTION><OPTION value=8 >vida</OPTION><OPTION value=9 >smartcon</OPTION><OPTION value=10 >auvtech</OPTION><OPTION value=11 >ringtec</OPTION><OPTION value=12 >citron</OPTION><OPTION value=13 SELECTED>asiasoft</OPTION><OPTION value=14 >txtc</OPTION><OPTION value=15 >i-fone</OPTION><OPTION value=16 >suntek</OPTION><OPTION value=17 >asiainfo</OPTION><OPTION value=18 >lucent</OPTION><OPTION value=19 >ipn</OPTION><OPTION value=20 11:00)......,..........</OPTION><OPTION value=2 >(GMT-10:00)......</OPTION><OPTION value=3 >(GMT-09:00)........</OPTION><OPTION value=4 >(GMT-08:00)..........(............)</OPTION><OPTION value=5 >(GMT-07:00)........(............)</OPTION><OPTION value=6 >(GMT-07:00)........</OPTION><OPTION value=7 >(GMT-06:00)........</OPTION><OPTION value=8 >(GMT-06:00)..........</OPTION><OPTION value=9 >(GMT-06:00)........(............)</OPTION><OPTION value=10 >(GMT-06:00)......</OPTION><OPTION value=11 >(GMT-05:00)......,....</OPTION><OPTION value=12 >(GMT-05:00)........(............)</OPTION><OPTION value=13 >(GMT-05:00)........(..)</OPTION><OPTION value=14 >(GMT-04:00)..........(......)</OPTION><OPTION value=15 >(GMT-04:00)........,......</OPTION><OPTION value=16 >(GMT-04:00)........</OPTION><OPTION value=17 >(GMT-03:30)......</OPTION><OPTION value=18 >(GMT-03:00)........</OPTION><OPTION value=19 >(GMT-03:00)..............</OPTION><OPTION value=20 >(GMT-03:00)......</OPTION><OPTION value=21 >(GMT-02:00)........</OPTION><OPTION value=22 >(GMT-01:00)..........</OPTION><OPTION value=23 >(GMT-01:00)..........</OPTION><OPTION value=24 >(GMT)......,......,....,......</OPTION><OPTION value=25 >(GMT)..........,........</OPTION><OPTION value=26 >(GMT+01:00)..........,......,....,..........</OPTION><OPTION value=27 >(GMT+01:00)..........,........,....</OPTION><OPTION value=28 >(GMT+01:00)........,........,......,....</OPTION><OPTION value=29 >(GMT+01:00)........,......,....</OPTION><OPTION value=30 >(GMT+01:00)........</OPTION><OPTION value=31 >(GMT+02:00)..........</OPTION><OPTION value=32 >(GMT+02:00)......</OPTION><OPTION value=33 >(GMT+02:00)....</OPTION><OPTION value=34 >(GMT+02:00)....</OPTION><OPTION value=35 >(GMT+02:00)....,..........</OPTION><OPTION value=36 >(GMT+02:00)........</OPTION><OPTION value=37 >(GMT+03:00)......</OPTION><OPTION value=38 >(GMT+03:00)......,......</OPTION><OPTION value=39 >(GMT+03:00)......,........</OPTION><OPTION value=40 >(GMT+03:00)......</OPTION><OPTION value=41 >(GMT+03:30)......</OPTION><OPTION value=42 >(GMT+04:00)........,........</OPTION><OPTION value=43 >(GMT+04:00)....</OPTION><OPTION value=44 >(GMT+04:30)......</OPTION><OPTION value=45 >(GMT+05:00)..........</OPTION><OPTION value=46 >(GMT+05:00)........,......</OPTION><OPTION value=47 >(GMT+05:30)........,....,......</OPTION><OPTION value=48 >(GMT+05:45)........</OPTION><OPTION value=49 >(GMT+06:00)..........</OPTION><OPTION value=50 >(GMT+06:00)....</OPTION><OPTION value=51 >(GMT+06:00)..................</OPTION><OPTION value=52 >(GMT+06:30)....</OPTION><OPTION value=53 >(GMT+07:00)................</OPTION><OPTION value=54 >(GMT+07:00)....,......,....</OPTION><OPTION value=55 SELECTED>(GMT+08:00)....,....,........</OPTION><OPTION value=56 >(GMT+08:00)......,......</OPTION><OPTION value=57 >(GMT+08:00)....</OPTION><OPTION value=58 >(GMT+08:00)....</OPTION><OPTION value=59 >(GMT+08:00)........</OPTION><OPTION value=60 >(GMT+09:00)....,....,....</OPTION><OPTION value=61 >(GMT+09:00)....</OPTION><OPTION value=62 >(GMT+09:00)........</OPTION><OPTION value=63 >(GMT+09:30)........</OPTION><OPTION value=64 >(GMT+09:30)......</OPTION><OPTION value=65 >(GMT+10:00)........</OPTION><OPTION value=66 >(GMT+10:00)..............</OPTION><OPTION value=67 >(GMT+10:00)....,..........</OPTION><OPTION value=68 >(GMT+10:00)......</OPTION><OPTION value=69 >(GMT+10:00)......,......,....</OPTION><OPTION value=70 >(GMT+11:00)......,..........</OPTION><OPTION value=71 >(GMT+12:00)..........,..........</OPTION><OPTION value=72 >(GMT+12:00)......,......</OPTION><OPTION value=73 >(GMT+13:00)..........</OPTION></SELECT></td></tr></table></div><center><input type=submit value=" ........ " name=update>&nbsp;&nbsp;<input type=submit value=" ...... " name=addressbook>&nbsp;&nbsp;<input type=submit value=".............." name=upgrade></center></form></body></html>POST /b HTTP/1.1

这是我抓包抓来的,请大家看看,我的目的是得到其中的数据,比如value=192.168.0.123我要的就是这个IP地址,和前面<td>IP</td>里的IP,以便我能知道这是一个什么值,然后再调用其他函数用这个值,希望各位大哥能给我个程序或者办法取道这个值,并知道它是个什么值。

搜索更多相关主题的帖子: html 解析 
2006-02-17 22:25
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
得分:0 

int main(void)
{
char str[20];
char str1[20];
int i=0,t=0 ;

while(scanf("%s ",str)!=EOF)//怎么读怎么处理是你的事,这里是用文本读,将上面的html存作为文本利用dos重定向 test.exe < 1.txt
{
if(strlen(str)>=13)
if(!strncmp(str,"value=",6))
{
i=0 ;
while((str1[i]=str[6+i])!=0)i++;
str1[i+1]=0 ;
i=0,t=0 ;
while(str1[i])
{
if(str1[i]=='.')t++;
i++;
}
if(t==3)printf("%s\n",str1);//输出IP
}

}
return 0;
}

随手写一个,未调试,自己看着改吧

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2006-02-17 23:14
Knocker
Rank: 8Rank: 8
等 级:贵宾
威 望:47
帖 子:10454
专家分:603
注 册:2004-6-1
得分:0 
假如你会用THTML之类的控件就更简单了

九洲方除百尺冰,映秀又遭蛮牛耕。汽笛嘶鸣国旗半,哀伤尽处是重生。     -老K
治国就是治吏。礼义廉耻,国之四维。四维不张,国之不国。   -毛泽东
2006-02-17 23:16
aiyuheng
Rank: 1
等 级:新手上路
威 望:1
帖 子:656
专家分:0
注 册:2006-1-12
得分:0 
K老大今天这么有空呢??

when i want to ask anyone,i will ask myself first.
2006-02-17 23:39
baidu
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:3811
专家分:0
注 册:2005-11-4
得分:0 
唉,失意中....只好化悲愤为力量了

偶放弃所有文章版权,偶在BCCN论坛任何贴子,可转贴,可散发,可抄袭,可复制,可被冒名顶替,可被任何人引用到任何文章中且不写出引文出处,偶分文不取。
2006-02-17 23:43
黑白格子布
Rank: 1
等 级:新手上路
威 望:1
帖 子:67
专家分:0
注 册:2005-12-11
得分:0 

2006-02-18 14:45
天晶子剑
Rank: 1
等 级:新手上路
帖 子:77
专家分:0
注 册:2006-2-13
得分:0 
什么呀,晕死了。
2006-02-19 13:58
history_sky
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2005-12-14
得分:0 

谢谢大哥指教,我当研读,有不懂之处,还望再加指教。

2006-02-20 21:13
history_sky
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2005-12-14
得分:0 
k哥:
请您指教一下我如何得到页面上的全部数据,不光是IP,其他的也要,还有就是我不光得到他们,还要知道他们是什么,比如我得到了192.168.0.123,我还要知道它是ip,我好去调其他的函数处理它。
2006-02-20 21:42



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-46035-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.490023 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved