473,396 Members | 1,982 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to Split HTML String?

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.

Feb 7 '07 #1
10 5487
<vu******@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
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)


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.
Feb 7 '07 #2
wrote on 07 feb 2007 in microsoft.public.inetserver.asp.general:
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)
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)
Feb 7 '07 #3

<vu******@gmail.comwrote in message
news:11*********************@h3g2000cwc.googlegrou ps.com...
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 is correct, it should work

try

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

thi should show you what your working with
Feb 7 '07 #4
On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsITwrote:
<vunet...@gmail.comwrote in message

news:11*********************@h3g2000cwc.googlegrou ps.com...
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 is correct, it should work

try

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

thi should show you what your working with
Dear experts!
If this will work:
dim a, b
a = "aaa<!--item code separator-->bbb"
b = split(a,"<!--item code xxxxxx separator-->")
response.write b(0) '' aaa
response.write b(1) '' bbb

this won't:
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 a: a= Server.HTMLEncode(strHTML)
b = split(a,"<!--item code separator-->") 'THIS DOES NOT WORK
response.write b(0) '' aaabbb
response.write b(1) '' error

It must be because of the data type or something I suspect? But
cStr(a) does not help too. Also, there is <!--item code separator-->
in that code, for sure!
Thank you all.

Feb 7 '07 #5
wrote on 07 feb 2007 in microsoft.public.inetserver.asp.general:
On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsITwrote:
><vunet...@gmail.comwrote in message
[..]
>>
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
Dear experts!
If this will work:
dim a, b
a = "aaa<!--item code separator-->bbb"
b = split(a,"<!--item code xxxxxx separator-->")
response.write b(0) '' aaa
response.write b(1) '' bbb

this won't:
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 a: a= Server.HTMLEncode(strHTML)
b = split(a,"<!--item code separator-->") 'THIS DOES NOT WORK
response.write b(0) '' aaabbb
response.write b(1) '' error

It must be because of the data type or something I suspect? But
cStr(a) does not help too. Also, there is <!--item code separator-->
in that code, for sure!
Thank you all.
You are wrong pointing at in the error line,
because the error text you quoted was:
>Microsoft VBScript runtime error '800a0009'
Subscript out of range: '[number: 1]'
/get_item.asp, line 55
being about a nonexistent subscript,
it cannot have been the line with the split()
but it mut have been this line:
> response.write HTMLArr(1)
Conclusion: the split() works OK,
but there is no HTMLArr(1),
so the split did not find the string searched for
and returned an array with only one member.

QED.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 7 '07 #6
vu******@gmail.com wrote:
On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsITwrote:
Dim a: a= Server.HTMLEncode(strHTML)
Do this:
Response.Write a

run the page and view source. Do you see <!--item code separator--in
the source?

Or do you see something like this:
&lt;!--item code separator--&gt;

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 7 '07 #7
On Feb 7, 11:31 am, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
vunet...@gmail.com wrote:
On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsITwrote:
Dim a: a= Server.HTMLEncode(strHTML)

Do this:
Response.Write a

run the page and view source. Do you see <!--item code separator--in
the source?

Or do you see something like this:
&lt;!--item code separator--&gt;

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
when I do what you say:
HTMLArr = split(FullHTML,"<!--item code separator-->")
I only get:
response.write HTMLArr(0)
and HTMLArr(0) does contain 2 lines of <!--item code separator-->

Just copy and paste this code to ASP page to see it not working, if
you can, and let me know, if possible:
(not, this is a fake example)

Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://devguru.com/technologies/
javascript/home.asp", False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
response.write HTMLArr(1)
Thanks
Feb 7 '07 #8
vu******@gmail.com wrote:
>
when I do what you say:
HTMLArr = split(FullHTML,"<!--item code separator-->")
I only get:
response.write HTMLArr(0)
and HTMLArr(0) does contain 2 lines of <!--item code separator-->
No no no
response.Write FullHTML. Run the page. View Source. Do you see "<!--item
code separator-->" or "&lt;!--item code separator--&gt;"?
>
Just copy and paste this code to ASP page to see it not working, if
you can, and let me know, if possible:
(not, this is a fake example)

Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://devguru.com/technologies/
javascript/home.asp", False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
response.write HTMLArr(1)
OK, I guess I have to lead you by the hand. :-)
After using HTMLEncode, your string no longer contains "<!-- Main
Content Begins -->". It contains "&lt;!-- Main Content Begins --&gt;", a
fact which you can ascertain by writing the string to response, running
the page and viewing source. You either have to do this:

strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = strHTML
HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
response.write Server.HTMLEncode(HTMLArr(1))

or this:

strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
response.write HTMLArr(1)


--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Feb 7 '07 #9
On Feb 7, 1:26 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
vunet...@gmail.com wrote:
when I do what you say:
HTMLArr = split(FullHTML,"<!--item code separator-->")
I only get:
response.write HTMLArr(0)
and HTMLArr(0) does contain 2 lines of <!--item code separator-->

No no no
response.Write FullHTML. Run the page. View Source. Do you see "<!--item
code separator-->" or "&lt;!--item code separator--&gt;"?


Just copy and paste this code to ASP page to see it not working, if
you can, and let me know, if possible:
(not, this is a fake example)
Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://devguru.com/technologies/
javascript/home.asp", False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
response.write HTMLArr(1)

OK, I guess I have to lead you by the hand. :-)
After using HTMLEncode, your string no longer contains "<!-- Main
Content Begins -->". It contains "&lt;!-- Main Content Begins --&gt;", a
fact which you can ascertain by writing the string to response, running
the page and viewing source. You either have to do this:

strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = strHTML
HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
response.write Server.HTMLEncode(HTMLArr(1))

or this:

strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
response.write HTMLArr(1)

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
oh, I did not know that <!-- will become &lt;!-- during this
encoding... Now I see. Allow me to fix this and I will come back here
with confirmation. Sorry, but within 6 hours from now. Thank you for
leading me by your hand!

Feb 7 '07 #10
On Feb 7, 2:23 pm, vunet...@gmail.com wrote:
On Feb 7, 1:26 pm, "Bob Barrows [MVP]" <reb01...@NOyahoo.SPAMcom>
wrote:
vunet...@gmail.com wrote:
when I do what you say:
HTMLArr = split(FullHTML,"<!--item code separator-->")
I only get:
response.write HTMLArr(0)
and HTMLArr(0) does contain 2 lines of <!--item code separator-->
No no no
response.Write FullHTML. Run the page. View Source. Do you see "<!--item
code separator-->" or "&lt;!--item code separator--&gt;"?
Just copy and paste this code to ASP page to see it not working, if
you can, and let me know, if possible:
(not, this is a fake example)
Dim objXmlHttp
Dim strHTML
Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
objXmlHttp.open "GET", "http://devguru.com/technologies/
javascript/home.asp", False
objXmlHttp.send
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
response.write HTMLArr(1)
OK, I guess I have to lead you by the hand. :-)
After using HTMLEncode, your string no longer contains "<!-- Main
Content Begins -->". It contains "&lt;!-- Main Content Begins --&gt;", a
fact which you can ascertain by writing the string to response, running
the page and viewing source. You either have to do this:
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = strHTML
HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
response.write Server.HTMLEncode(HTMLArr(1))
or this:
strHTML = objXmlHttp.responseText
Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
response.write HTMLArr(1)
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

oh, I did not know that <!-- will become &lt;!-- during this
encoding... Now I see. Allow me to fix this and I will come back here
with confirmation. Sorry, but within 6 hours from now. Thank you for
leading me by your hand!
just an update: IT WORKS WELL WITH
HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
Thank you

Feb 8 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
5
by: Andy Mee | last post by:
Hello one and all, I'm developing an Asp.NET system to take a CSV file uploaded via the web, parse it, and insert the values into an SQL database. My sticking point comes when I try to split()...
4
by: Varad | last post by:
I'm trying to break this html statement at the "<!---->" <br><a href='www.link1.com'>Link1</a><!----><br><a href='www.link2.com'>Link2</a><!----><br><a href='www.link3.com'>Link3</a><!----> ...
19
by: David Logan | last post by:
We need an additional function in the String class. We need the ability to suppress empty fields, so that we can more effectively parse. Right now, multiple whitespace characters create multiple...
3
by: Ben | last post by:
Hi I am creating a dynamic function to return a two dimensional array from a delimeted string. The delimited string is like: field1...field2...field3... field1...field2...field3......
4
by: Michele Petrazzo | last post by:
Hello ng, I don't understand why split (string split) doesn't work with the same method if I can't pass values or if I pass a whitespace value: >>> "".split() >>> "".split(" ") But into...
3
by: edoardo.poeta | last post by:
I'm a dummy. I have a basic knowledge of javascript and I want to split a string, but I receive an error at line 15. Where my error in make the array? Why? Can someone help me to resolve? Thank's....
4
by: Steven D'Aprano | last post by:
I'm having problems passing a default value to the maxsplit argument of str.split. I'm trying to write a function which acts as a wrapper to split, something like this: def mysplit(S, sep=None,...
14
by: Stevo | last post by:
If you split a string into an array using the split method, it's not working the way I'd expect it to. That doesn't mean it's wrong of course, but would anyone else agree it's working somewhat...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.