如何拆分HTML字符串? [英] How to Split HTML String?

查看:89
本文介绍了如何拆分HTML字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我使用XMLHTTP获取另一个页面的HTML。然后,我需要削减HTML字符串的一些中间部分,但是我遇到了问题(请参阅下面的注释

)。我在response.write生成的错误(因为

它没有拆分)是:


Microsoft VBScript运行时错误''800a0009''
下标超出范围:''[数字:1]''

/get_item.asp,第55行

Dim objXmlHttp

Dim strHTML

设置objXmlHttp = Server.CreateObject(" Msxml2.ServerXMLHTTP")

objXmlHttp.open" GET"," http: //www.site.com/item.asp?id=10,False

objXmlHttp.send

strHTML = objXmlHttp.responseText

Dim FullHTML:FullHTML = Server.HTMLEncode(strHTML)

HTMLArr = split(FullHTML,"! - - item code separator - >")''这不会

SPLIT

response.write HTMLArr(1)

dim PureHTML:PureHTML = FullHTML''HTMLArr(1)


请建议。

Hello,
I use XMLHTTP to get an HTML of another page. Then, I need to cut some
middle part of that HTML string but I have problems doing it (see note
in caps below). The error I have generated at response.write (because
it does not split) is:

Microsoft VBScript runtime error ''800a0009''
Subscript out of range: ''[number: 1]''
/get_item.asp, line 55

Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!--item code separator-->") ''THIS DOES NOT
SPLIT
response.write HTMLArr(1)

dim PureHTML : PureHTML = FullHTML ''HTMLArr(1)

Please, suggest.

推荐答案

< vu ****** @ gmail.comwrote in message

新闻: 11*********************@h3g2000cwc.googlegrou ps.com ...
<vu******@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...

你好,

我使用XMLHTTP获取另一个页面的HTML。然后,我需要削减HTML字符串的一些中间部分,但是我遇到了问题(请参阅下面的注释

)。我在response.write生成的错误(因为

它没有拆分)是:


Microsoft VBScript运行时错误''800a0009''
下标超出范围:''[数字:1]''

/get_item.asp,第55行

Dim objXmlHttp

Dim strHTML

设置objXmlHttp = Server.CreateObject(" Msxml2.ServerXMLHTTP")

objXmlHttp.open" GET"," http: //www.site.com/item.asp?id=10,False

objXmlHttp.send

strHTML = objXmlHttp.responseText

Dim FullHTML:FullHTML = Server.HTMLEncode(strHTML)

HTMLArr = split(FullHTML,"! - - item code separator - >")''这不会

SPLIT

response.write HTMLArr(1)

dim PureHTML:PureHTML = FullHTML''HTMLArr(1)
Hello,
I use XMLHTTP to get an HTML of another page. Then, I need to cut some
middle part of that HTML string but I have problems doing it (see note
in caps below). The error I have generated at response.write (because
it does not split) is:

Microsoft VBScript runtime error ''800a0009''
Subscript out of range: ''[number: 1]''
/get_item.asp, line 55

Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!--item code separator-->") ''THIS DOES NOT
SPLIT
response.write HTMLArr(1)

dim PureHTML : PureHTML = FullHTML ''HTMLArr(1)




您是否想要拆分字符串?

您的示例显示:

"<! - -item code sepa rator - >"


Split()中的分隔符只有一个字符?


语法

分割(表达式[,分隔符[,计数[,比较]]])

表达式 - 必需。

分隔符 - 可选。

用于标识子字符串限制的字符串字符。

如果省略,则为空格字符( )假定是

分隔符。

如果没有,则发布需要拆分的字符串示例

和你的Split()语句。


如何检索字符串(只要它存在)无关紧要。



Are you trying to split on a string?
Your example shows this:
"<!--item code separator-->"

The delimiter in Split() is only one character?

Syntax
Split(expression[, delimiter[, count[, compare]]])
expression -- Required.
delimiter -- Optional.
String character used to identify substring limits.
If omitted, the space character (" ") is assumed to be the
delimiter.

If not then post an example of the string that needs to be split
along with your Split() statement.

How the string is retrieved (as long as it exists) doesn''t matter.


于2007年2月7日在microsoft.public.inetserver.asp.general中写道:
wrote on 07 feb 2007 in microsoft.public.inetserver.asp.general:

您好,

我使用的是XMLHTTP获取另一个页面的HTML。然后,我需要削减HTML字符串的一些中间部分,但是我遇到了问题(请参阅下面的注释

)。我在response.write生成的错误(因为

它没有拆分)是:


Microsoft VBScript运行时错误''800a0009''
下标超出范围:''[数字:1]''

/get_item.asp,第55行

Dim objXmlHttp

Dim strHTML

设置objXmlHttp = Server.CreateObject(" Msxml2.ServerXMLHTTP")

objXmlHttp.open" GET"," http: //www.site.com/item.asp?id=10,False

objXmlHttp.send

strHTML = objXmlHttp.responseText

Dim FullHTML:FullHTML = Server.HTMLEncode(strHTML)

HTMLArr = split(FullHTML,"! - 项代码分隔符 - >")

' '这不会分裂

response.write HTMLArr(1)
Hello,
I use XMLHTTP to get an HTML of another page. Then, I need to cut some
middle part of that HTML string but I have problems doing it (see note
in caps below). The error I have generated at response.write (because
it does not split) is:

Microsoft VBScript runtime error ''800a0009''
Subscript out of range: ''[number: 1]''
/get_item.asp, line 55

Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!--item code separator-->")
''THIS DOES NOT SPLIT
response.write HTMLArr(1)



它应该可以工作,通过反复试验来测试:


< script type =''text / vbscript''>


a =" aaa<! - 商品代码分隔符 - > bbb"

b = split(a,"<! - 商品代码分隔符 - >")

alert(b (0))''''aaa

提醒(b(1))''''bbb


< / script>


我怀疑字符串FullHTML不包含搜索字符串。


测试:


response.write HTMLArr(0)& " br>"

response.write HTMLArr(1)


或者:


< script type =''text / vbscript''>


a =" aaa<! - 商品代码分隔符 - > bbb"

b = split(a,"<! - item code xxxxxx separator - >")

alert(b(0))''''aaa<! - 项目代码分隔符 - > bbb

alert(b(1))''''错误


< / script>

-

Evertjan。

荷兰。

(请将x''es更改为我的电子邮件地址中的点数)

It should work, test by trial and error:

<script type=''text/vbscript''>

a = "aaa<!--item code separator-->bbb"
b = split(a,"<!--item code separator-->")
alert(b(0)) '''' aaa
alert(b(1)) '''' bbb

</script>

I suspect the string FullHTML does not contain the search string.

Test by:

response.write HTMLArr(0) & "<br>"
response.write HTMLArr(1)

or by:

<script type=''text/vbscript''>

a = "aaa<!--item code separator-->bbb"
b = split(a,"<!--item code xxxxxx separator-->")
alert(b(0)) '''' aaa<!--item code separator-->bbb
alert(b(1)) '''' error

</script>

--
Evertjan.
The Netherlands.
(Please change the x''es to dots in my emailaddress)




< vu ****** @ gmail.comwrote in message

news:11 * ********************@h3g2000cwc.googlegrou ps.com ...

<vu******@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...

您好,

我使用XMLHTTP获取另一个页面的HTML。然后,我需要削减HTML字符串的一些中间部分,但是我遇到了问题(请参阅下面的注释

)。我在response.write生成的错误(因为

它没有拆分)是:


Microsoft VBScript运行时错误''800a0009''
下标超出范围:''[数字:1]''

/get_item.asp,第55行

Dim objXmlHttp

Dim strHTML

设置objXmlHttp = Server.CreateObject(" Msxml2.ServerXMLHTTP")

objXmlHttp.open" GET"," http: //www.site.com/item.asp?id=10,False

objXmlHttp.send

strHTML = objXmlHttp.responseText

Dim FullHTML:FullHTML = Server.HTMLEncode(strHTML)

HTMLArr = split(FullHTML,"! - - item code separator - >")''这不会

SPLIT

response.write HTMLArr(1)

dim PureHTML:PureHTML = FullHTML''HTMLArr(1)


请建议。
Hello,
I use XMLHTTP to get an HTML of another page. Then, I need to cut some
middle part of that HTML string but I have problems doing it (see note
in caps below). The error I have generated at response.write (because
it does not split) is:

Microsoft VBScript runtime error ''800a0009''
Subscript out of range: ''[number: 1]''
/get_item.asp, line 55

Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!--item code separator-->") ''THIS DOES NOT
SPLIT
response.write HTMLArr(1)

dim PureHTML : PureHTML = FullHTML ''HTMLArr(1)

Please, suggest.



Evertjan是正确的,它应该可以工作


试试

每个
HTMLAr中的东西

response.write thing& < br>"

next


thi应该显示你的工作原理

Evertjan is correct, it should work

try

for each thing in HTMLAr
response.write thing & "<br>"
next

thi should show you what your working with


这篇关于如何拆分HTML字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆