Results 1 to 11 of 11

Thread: [RESOLVED] How can i Parse a html page.

  1. #1

    Thread Starter
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Resolved [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.

  2. #2
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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:

    HTML Code:
    <textarea>
    You can do this by typing:
    VB Code:
    1. 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:

    HTML Code:
    </textarea>
    or whatever the ending HTML tag is.

    You can do that by typing:

    VB Code:
    1. 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.

  3. #3

    Thread Starter
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Arrow 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.

  4. #4
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: How can i Parse a html page.

    I wrote a function for you to parse out the Text.

    VB Code:
    1. Private Function GetTextArea(HTML As String) As String
    2.     '<center><textarea cols="60" rows="15">This text I want to copy in my Textbox or listbox of my VB6 appliation.</textarea></center>
    3.     Dim lonStart As Long, lonEnd As Long
    4.     Dim strStart As String, lonLenStart As Long
    5.    
    6.     strStart = "<textarea"
    7.     lonLenStart = Len(strStart)
    8.     'Find the starting of TextArea tag (<textarea
    9.     'since <textarea has properties we will search for <textarea and not <textarea>
    10.    
    11.     'vbTextCompare makes it so it's not case-sensitive.
    12.     'So if it's <TEXTAREA it will still find it.
    13.     lonStart = InStr(1, HTML, strStart, vbTextCompare)
    14.    
    15.     If lonStart > 0 Then
    16.         'Found <textarea
    17.         'Find closing tag to textarea (>)
    18.         lonStart = InStr(lonStart + 1, HTML, ">")
    19.        
    20.         If lonStart > 0 Then
    21.             'Find closing tag to text area. Now find end of text area (</textarea)
    22.             lonEnd = InStr(lonStart, HTML, "</textarea>", vbTextCompare)
    23.            
    24.             If lonEnd > 0 Then
    25.                 'Use the Mid$() statement to grab the text between the tags.
    26.                 GetTextArea = Mid$(HTML, lonStart + 1, (lonEnd - lonStart) - 1)
    27.             End If
    28.        
    29.         End If
    30.    
    31.     End If
    32.    
    33. End Function

    And I attached a sample project below.

    Hope this helps.
    Last edited by DigiRev; Mar 26th, 2007 at 02:55 AM.

  5. #5

    Thread Starter
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Thumbs up 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..

  6. #6

    Thread Starter
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Arrow 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

  7. #7
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    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.

  8. #8

    Thread Starter
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Thumbs up 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

  9. #9

    Thread Starter
    Lively Member Nerd-Man's Avatar
    Join Date
    Dec 2006
    Location
    India
    Posts
    119

    Arrow 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.

  10. #10
    New Member
    Join Date
    Mar 2008
    Posts
    1

    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

  11. #11
    "Digital Revolution"
    Join Date
    Mar 2005
    Posts
    4,471

    Re: How can i Parse a html page.

    Quote 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
  •  



Click Here to Expand Forum to Full Width