VB批量修改htm网页的问题 清除1.htm-100.htm中的 <!-- 和-->之间的内容 或者将<!-- 和-->也去掉更好
比如 
</div><br>
<!--
<form name=f2 action="/s">
<tr valign="middle">
<td nowrap>
<input type=hidden name=ct value="0">
<input type=hidden name=ie value="gb2312">
<input type=hidden name=bs value="qq">
<input type=hidden name=sr>
<input type=hidden name=z value="">
<input type=hidden name=cl value=3>
<input type=hidden name=f value=8>
<input name=wd size="35" class=i value="啊" maxlength=100>
<input type=submit value=暗暗> <input type=button value=结果中找 onclick="return bq(f2,1,0);">&nbsp;&nbsp;&nbsp;</td>
<td nowrap><a href="http://utility.baidu.com/quality/quality_form.php?word=qq%BF%D5%BC%E4%C3%E2%B7%D1%C6%A4%B7%F4">-->
</tr>
只留下</div><br>
</tr>
这样,如何能实现呢? 要批量处理哦参考代码:For i = 1 To shuliang.Text '文件数量Dim S1 As String
Dim d As String
DownloadFile "  http://www.baidu.com/s?wd=" + GetaLine(RichTextBox2, i - 1) + "&cl=3", mulu & qianzhui.Text & "" & i & "." + houzhui.TextIf d = "" Then
    Open mulu & qianzhui.Text & "" & i & "." + houzhui.Text For Input As #3    Do Until EOF(3)
        Line Input #3, S1
        d = d & S1 & vbCrLf
    Loop    Close #3
    d = Replace(d, "<!--STATUS OK-->", "")
End IfOpen mulu & qianzhui.Text & "" & i & "." + houzhui.Text For Output As #4
Print #4, d
Close #4
Close #2 '写完就关这只是批量生成 修改  并保存的 大家也看到了 抓取的内容都不一样 所以无法和
    d = Replace(d, "<!--STATUS OK-->", "")
 这段一样去掉一些代码  请求帮助!

解决方案 »

  1.   

    说个思路:因为"<!--"和"-->"是成对出现的,所以你同时打开输入文件和输出文件
        Dim bStartDel As Boolean
        bStartDel = False
        Dim strInput As String, strOutput As String
        Dim iIndex As Integer
        
        Open "input.htm" For Input As #1
            Open "output.htm" For Output As #2
                Do Until EOF(1)
                    Line Input #1, strInput
                    If (bStartDel) Then     '要找的是"-->"
                        iIndex = InStr(1, strInput, "-->", vbTextCompare)
                        If (iIndex > 0) Then
                            bStartDel = False
                            '取多少个字符可能还需要再调整调整,加1减1的。
                            strOutput = Right(strInput, Len(strInput) - iIndex)
                        End If
                    Else                    '要找的是"<!--"
                        iIndex = InStr(1, strInput, "<!--", vbTextCompare)
                        If (iIndex > 0) Then
                            bStartDel = True
                             '取多少个字符可能还需要再调整调整,加1减1的。
                            strOutput = Left(strInput, iIndex)
                        Else
                            strOutput = strInput
                        End If
                    End If
                    Write #2, strOutput
                Loop
            Close #2
        Close #1
      

  2.   

    你的问题可以找支持模式匹配的替换的批量替换工具,以前我用过的.应该google一下可以找到.
      

  3.   

    将 html 全部读到一个字符串 s 中
    lLastPos = 0
    while lLastPos < len(s)
      i = instr(lLastPos+1, s, "<!--")
      if i = 0 then
        Write #2, mid$(s, lLastPos+1)
        lLastPos = Len(s)
      else
        j = instr(i+4, s, "-->")
        if j= 0 then err.raise 321 'Invalid file format
        Write #2, mid$(s, lLastPos+1, i-lLastPos-1)
        lLastPos = j+2
      end if
    wend