写了一个字符串函数,是把字符串中特定的字符串去掉
比如一个网页中含有<img src=.......>或<script type="text/javascript">....</script>这样的串,把它去掉 Public Function Kill_Some_html(strHtml, beginhtml, endhtml)
Dim pos, pos1, pos2, temp1, temp2,temp3
Dim i
i = Len(endhtml)
strHtml = LCase(strHtml)
pos = InStrB(1, strHtml, beginhtml, vbBinaryCompare) > 0
If pos Then
pos1 = InStrB(1, strHtml, beginhtml, vbBinaryCompare)
temp1 = MidB(strHtml, 1, pos1) //取得第一段
strHtml = MidB(strHtml, pos1)
pos2 = InStrB(1, strHtml, endhtml, vbBinaryCompare)
temp2 = MidB(strHtml, pos2 + i) //取得第二段
temp3 = temp1 & temp2
Kill_Some_html = temp1 & temp2
Else
Kill_Some_html = strHtml
End If
pos = InStrB(1, temp3, beginhtml, vbBinaryCompare) > 0
if pos then call Kill_Some_html(temp3, beginhtml, endhtml) //寻找下一个
End Function
===============
html_sourcecode_body = Kill_Some_html(html_sourcecode_body, "<script type=""text/javascript"">", "</script>")
html_sourcecode_body = Kill_Some_html(html_sourcecode_body, "<img", ">")
返回的字符串很奇怪,有的网页img(script)能去掉一个,有的一个也去不掉高手帮我看看,那里可能存在问题啊
比如一个网页中含有<img src=.......>或<script type="text/javascript">....</script>这样的串,把它去掉 Public Function Kill_Some_html(strHtml, beginhtml, endhtml)
Dim pos, pos1, pos2, temp1, temp2,temp3
Dim i
i = Len(endhtml)
strHtml = LCase(strHtml)
pos = InStrB(1, strHtml, beginhtml, vbBinaryCompare) > 0
If pos Then
pos1 = InStrB(1, strHtml, beginhtml, vbBinaryCompare)
temp1 = MidB(strHtml, 1, pos1) //取得第一段
strHtml = MidB(strHtml, pos1)
pos2 = InStrB(1, strHtml, endhtml, vbBinaryCompare)
temp2 = MidB(strHtml, pos2 + i) //取得第二段
temp3 = temp1 & temp2
Kill_Some_html = temp1 & temp2
Else
Kill_Some_html = strHtml
End If
pos = InStrB(1, temp3, beginhtml, vbBinaryCompare) > 0
if pos then call Kill_Some_html(temp3, beginhtml, endhtml) //寻找下一个
End Function
===============
html_sourcecode_body = Kill_Some_html(html_sourcecode_body, "<script type=""text/javascript"">", "</script>")
html_sourcecode_body = Kill_Some_html(html_sourcecode_body, "<img", ">")
返回的字符串很奇怪,有的网页img(script)能去掉一个,有的一个也去不掉高手帮我看看,那里可能存在问题啊
newhtml=""
for i=1 to len(strHtml)
if mid(strhtml,i,?)="<img src=.......>" then '?是要去掉的字符个数
i=i+?
end if
newhtml=newhtml+mid(strhtml,i,1)
next
'*******有特殊字符的部份,比如"号***********
for i=1 to len(strHtml)
if mid(strhtml,i,?)="<script type="& chr(34) & "text/javascript" & chr(34) & ">" then '?是要去掉的字符个数
i=i+?
end if
newhtml=newhtml+mid(strhtml,i,1)
next
我尽量不使用特殊符号,比如我只查找 "<script"
问题是:我的个数是未知的啊,那个<img 我不可能事先知道它的长度的
或者,如果你想删除XML中的节点的话,你可以引用 Microsoft XML, v2.0 或者v3.0,
然后使用XML对象来删除你想删除的节点。很简单的,慢慢玩一下?
对“使用XML对象来删除你想删除的节点“很敢兴趣
能提供一个代码实例吗
找出来使用呢