您的位置:程序门 -> vb -> 网络编程



正则用于vb读取网页的问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


正则用于vb读取网页的问题[已结贴,结贴人:glowing_yu]
发表于:2007-04-15 22:25:15 楼主
有这么一段代码:有用正则表达式匹配一个html标记: " <(.*)> .* <\/\1> "这个怎么用于匹配标记语言: <tr     class= "hover "   bgcolor= "#f5deb3 "   >
<td   width= "5% "   class= "tdh "> 1 </td>
<td   width= "60% "   class= "tdl "> 消息内容!! </td>
<td   width= "5% "   class= "tdh "> - </td>
<td   width= "5% "   class= "tdh "> ok </td>
<td   width= "5% "   class= "tdh "> - </td>
<td   width= "5% "   class= "tdh "> 有效 </td>
<td   width= "15% "   class= "tdh ">
<a   href= "?edit=15206&this_language=simplified&fr_show=1 "> 修改 </a>
/   <a   href= "?act=0&annix=15206&this_language=simplified&fr_show=1 "> 停用 </a>
/   <a   href= "?alert=15206&this_language=simplified&fr_show=1 "> 戒备 </a>
/   <a   href= "?del=15206&this_language=simplified&fr_show=1 "> 删除 </a>
</td>
<!--   [dts   460]   -   01/03/2006   (teh)   add   on   a   checkbox   for   marquee   function   start   -->
<td>
<input   type= "checkbox "   name= "fr_checker_15206 "   onclick= "marqueeshow( '15206 ') "   >
</td>
<!--   [dts   460]   -   01/03/2006   (teh)   add   on   a   checkbox   for   marquee   function   end   -->
</tr> 中的 <td   width= "60% "   class= "tdl "> 消息内容!! </td> 和 <input   type= "checkbox "   name= "fr_checker_15206 "   onclick= "marqueeshow( '15206 ') "   > ,也就是说我通过匹配提取该html语言中的:“消息内容”“15206”,用vb语言的
而我在正则写的代码是也就是匹配代码:
        dim   myreg   as   regexp
        dim   myreg1   as   regexp
        dim   objtemp     as   matchcollection                
        dim   i   as   integer
        set   myreg1   =   new   regexp        
        myreg1.ignorecase   =   true
        myreg1.global   =   true
        myreg1.multiline   =   true  
        set   myreg   =   new   regexp        
        myreg.ignorecase   =   true
        myreg.global   =   true
        myreg.multiline   =   true        
        myreg.pattern   =   " <td   width=\ "60%\ "   class=\ "tdl\ "> (.*) <\/td> "和
        myreg.pattern   =   " <input   type=\ "checkbox\ "   name=\ "fr_checker_(\d+)\ "   onclick=\ "marqueeshow\(\ '(\d+)\ '\)\ "   > "
但鼠标一离开就提示缺少语句错误,在正则里是可以这样匹配的,但用在vb程序中就出现错误提示,以前用正则匹配函数在vb中用这样的格式可以,但这个却不行啊,麻烦各位高手指点,小弟感激不尽,解决立即给分,谢谢
发表于:2007-04-16 07:07:131楼 得分:20
//鼠标一离开就提示缺少语句错误

字符串的问题

将myreg.pattern   =   " <td   width=\ "60%\ "   class=\ "tdl\ "> (.*) <\/td> "
修改为:
myreg.pattern   =   " <td   width=\ " "60%\ " "   class=\ " "tdl\ " "> (.*) <\/td> "
其余类似,简单的说,就是字串中的一个 ",要用两个 "代替
发表于:2007-04-16 08:53:002楼 得分:0
本想今天给楼主解决问题呢,楼主想出来了,按照老大的做法来吧
发表于:2007-04-16 09:06:043楼 得分:0
顺便问一下楼主以前的那个帖子来,怎么找不到了?
你这样只能匹配这两句话的并不能匹配你要的字符串啊?
发表于:2007-04-16 10:24:304楼 得分:80
首先建议楼主先把这两个字符串提取出来,


function   func_regexptest1(patrn,   strng)   as   boolean   '正ze表da式匹配操作(?找个数)
dim   regex,   match,   matches
set   regex   =   new   regexp
regex.pattern   =   patrn
regex.ignorecase   =   true
regex.global   =   true
set   matches   =   regex.EXECute(strng)
for   each   match   in   matches
str1   =   str1   &   match.value
next
msgbox   str1
end   function
然后:
function   func_replacetest(patrn,   replstr,   str   as   string)   '正ze表da式匹配操作(替?)
dim   regex
set   regex   =   new   regexp
regex.pattern   =   patrn
regex.ignorecase   =   true
regex.global   =   true
regex.EXECute   (str)
str2   =   regex.replace(str,   replstr)
func_replacetest   =   true
end   function

str   =   " <td   width= " "60% " "   class= " "tdl " "> ([^> ]*) </td> ¦ <input   type= " "checkbox " "   name= " "fr_checker_(\d+) " " "
call   func_regexptest1(str, "楼主的html文本 ")
call   func_replacetest(str,   "$1$2 ",   str1)
msgbox   str2
发表于:2007-04-16 17:00:425楼 得分:0
此贴到此为止,等xiaolei1982(小磊)再另一个贴帮我解决或一起给分,谢谢xiaolei1982(小磊)   ,麻烦你再帮我想想我刚在另一个贴所说的情况
发表于:2007-04-17 13:29:576楼 得分:0
怎么回事啊,我为何不能发帖子,真奇怪,????我不能进入提问的页面????
发表于:2007-04-19 15:42:527楼 得分:0
你点击一个类,然后上面就有提问按钮拉


快速检索

最新资讯
热门点击