|
-
Dec 27th, 2006, 11:24 AM
#1
Thread Starter
Lively Member
[RESOLVED] How can i Parse a html page.
hello,
im new to vb6 as well to this forum. i started progrmming 6 months ago and now i want to grab the contents of the textarea from a html page so that i dont have to copy and pase it. but i am not sure how to do it. however i have found the code to grab the entire page not the the portion i want. so please help me how to do that. i tried all the forum but none have answered my post. i hope this forum will help me. so please help me and i will donate something at your paypal for yoru forum hosting.
-
Dec 27th, 2006, 01:22 PM
#2
Re: How can i Parse a html page.
There's no real way to teach you how to parse an HTML page because it really depends on the page you're parsing. Every site is different.
You need to learn string manipulation. There's a lot of tutorials on this and a lot of threads on this forum.
You should learn how to use these functions:
InStr()
InStrRev()
Left$()
Mid$()
Right$()
and possibly Split() but I don't usually use Split() when parsing HTML.
You need to find the starting position of where the data is you want to extract, ie:
You can do this by typing:
VB Code:
Position = InStr(1, HTML, "<textarea>", vbTextCompare)
That will return the starting position of <textarea>.
Then you need to find the ending position which would be:
or whatever the ending HTML tag is.
You can do that by typing:
VB Code:
EndPosition = InStr(StartPosition, HTML, "</textarea>", vbTextCompare)
Then you can get the data between those tags by using the Mid$() function.
If you can post the URL to the site you want to parse, then it will be easier to help you.
-
Dec 28th, 2006, 03:31 AM
#3
Thread Starter
Lively Member
Re: How can i Parse a html page.
thanks alot bro for your reply.
the html tag i want to grab from is below..
Code:
<center><textarea cols="60" rows="15">This text I want to copy in my Textbox or listbox of my VB6 appliation.</textarea></center>
the area "This text I want to copy in my Textbox or listbox of my VB6 appliation." is what i want to copy to my textbox or any other component like a listbox or Richtext. so please give me the code on how to do it so i can deploy it in my application. and which section on the forum have the html parse examples like let me know. thank you very much once again for your help.
-
Dec 28th, 2006, 04:21 PM
#4
Re: How can i Parse a html page.
I wrote a function for you to parse out the Text.
VB Code:
Private Function GetTextArea(HTML As String) As String
'<center><textarea cols="60" rows="15">This text I want to copy in my Textbox or listbox of my VB6 appliation.</textarea></center>
Dim lonStart As Long, lonEnd As Long
Dim strStart As String, lonLenStart As Long
strStart = "<textarea"
lonLenStart = Len(strStart)
'Find the starting of TextArea tag (<textarea
'since <textarea has properties we will search for <textarea and not <textarea>
'vbTextCompare makes it so it's not case-sensitive.
'So if it's <TEXTAREA it will still find it.
lonStart = InStr(1, HTML, strStart, vbTextCompare)
If lonStart > 0 Then
'Found <textarea
'Find closing tag to textarea (>)
lonStart = InStr(lonStart + 1, HTML, ">")
If lonStart > 0 Then
'Find closing tag to text area. Now find end of text area (</textarea)
lonEnd = InStr(lonStart, HTML, "</textarea>", vbTextCompare)
If lonEnd > 0 Then
'Use the Mid$() statement to grab the text between the tags.
GetTextArea = Mid$(HTML, lonStart + 1, (lonEnd - lonStart) - 1)
End If
End If
End If
End Function
And I attached a sample project below.
Hope this helps.
Last edited by DigiRev; Mar 26th, 2007 at 02:55 AM.
-
Dec 29th, 2006, 05:21 AM
#5
Thread Starter
Lively Member
Re: How can i Parse a html page.
wow thanks bro, you really did a big help to me. i will donate something to the forum to keep up your good work. you guys are great. i hope you dont mind if i bring all my programmers friends to his forum so that get help from your site. thanks alot once again for your help and happy new year..
-
Dec 29th, 2006, 05:24 AM
#6
Thread Starter
Lively Member
Re: How can i Parse a html page.
sorry to post again but i have a paypal account from where i can add my little contribution to your site. so what is your paypal email so i can add my little donation. thanks
-
Dec 29th, 2006, 07:49 AM
#7
Re: How can i Parse a html page.
No need to pay me I enjoy helping, that's why I come here. 
I appreciate the offer though.
-
Dec 29th, 2006, 09:15 AM
#8
Thread Starter
Lively Member
Re: How can i Parse a html page.
thanks bro, you have solved a big problem and now i dont have to copy and paste. i can directly do it from the program using your code and now its working perfectly. your great thanks alot
-
Feb 25th, 2007, 11:47 AM
#9
Thread Starter
Lively Member
Re: How can i Parse a html page.
hi bro DigiRev, i got another problem. this time i want to add the lines btween the textarea to a list box like the example below:
what i want to do is copy each line inside the text area to the list box. if you can help me then i would be really greatful...
Last edited by Nerd-Man; Mar 10th, 2007 at 10:04 AM.
-
Mar 23rd, 2008, 08:21 PM
#10
New Member
Re: How can i Parse a html page.
heya digi i am trying to parse a site to extract text from it obviously, i am having a lil trouble with that code that you just posted for nerd-man, i can give you the link if you would like to help me parse it, isn't much there or just email me at [email protected] on this matter thanks much bud
-
Mar 24th, 2008, 10:53 PM
#11
Re: How can i Parse a html page.
 Originally Posted by dizzog
heya digi i am trying to parse a site to extract text from it obviously, i am having a lil trouble with that code that you just posted for nerd-man, i can give you the link if you would like to help me parse it, isn't much there or just email me at [email protected] on this matter thanks much bud
Sent an e-mail.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|