[VB6] Getting HTML Strings from a Web Page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bugmenot
    Banned
    New Member
    • Dec 2007
    • 5

    [VB6] Getting HTML Strings from a Web Page

    So I want to get some text from a web page and get it to show up in my program. Here's the part that has what I want:

    Code:
    	<div style="float: right; clear: right; background: #1daa42; color: #FFF; padding: 3px; border: 1px solid #000;">Online</div><br /><br />
    <div style="float: left; clear: left; padding: 3px;">  					Players Online:  				</div>  				524			</div>	  		</div>
    I want to get the "524", but it's always changing.
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Thats probably because the value of the "Players Online" is written from a server variable within code.

    You would need access to that server and\or web service to be able to get the value of that variable at any given time. Or the page would have to have a .txt file that it continually writes to that you could read from or something.

    Either way the fact that it is always changing would also mean that your program will have to always be refreshing the value as well so you could keep up. (i.e. rechecking the variable in a timed loop, or a loop triggered by an event such as a refresh button)

    Comment

    • jeffstl
      Recognized Expert Contributor
      • Feb 2008
      • 432

      #3
      Actually the more I think about it the more its ALREADY writing it to a .txt file. That is the source file you posted is going to have to be your source.

      You would have to select the whole string and trim out that part that you want.

      You would just have to do this over and over again in a loop to keep getting the latest one, or a refresh button.

      Comment

      • CodeButcher
        New Member
        • May 2007
        • 5

        #4
        You have this line in your file:
        " Players Online: </div> 524 </div>"
        So you therefore read in the textfile and search for the string "Players Online:"

        that gives you the location of this:
        " </div> 524 </div>..."
        So replace spaces with nothing and you get:
        "</div>524</div>..."
        Now search for the location of the first >"
        6. So, read from the 7th position to the next instance for the <"

        Something like value.substring (7, instr(value, 7, "<"))

        Then you get the number.

        Comment

        • bugmenot
          Banned
          New Member
          • Dec 2007
          • 5

          #5
          Originally posted by CodeButcher
          You have this line in your file:
          " Players Online: </div> 524 </div>"
          So you therefore read in the textfile and search for the string "Players Online:"

          that gives you the location of this:
          " </div> 524 </div>..."
          So replace spaces with nothing and you get:
          "</div>524</div>..."
          Now search for the location of the first >"
          6. So, read from the 7th position to the next instance for the <"

          Something like value.substring (7, instr(value, 7, "<"))

          Then you get the number.
          Ohh, okay. Could you give me an example though? I've never done something like this before so I have no idea.

          Comment

          • bugmenot
            Banned
            New Member
            • Dec 2007
            • 5

            #6
            *Sigh*

            Anyone wanna help? <_<

            Comment

            • jeffstl
              Recognized Expert Contributor
              • Feb 2008
              • 432

              #7
              Originally posted by bugmenot
              *Sigh*

              Anyone wanna help? <_<
              Multiple steps though. Which do you need help with?

              You need to read in your file (Open FileName as Input #1)

              Code:
              Open FilePath For Input As MyFile
              Do While Not EOF(MyFile)
                 Line Input #MyFile, sNextLine
                 sNextLine = sNextLine & vbCrLf
                 sText = sText & sNextLine
              Loop
              Text1.Text = sText
              Close MyFile

              Then you need to read in the string and do your selection using the string manipulation functions which are posted here.

              Comment

              • pureenhanoi
                New Member
                • Mar 2007
                • 175

                #8
                Originally posted by jeffstl
                Multiple steps though. Which do you need help with?

                You need to read in your file (Open FileName as Input #1)

                Code:
                Open FilePath For Input As MyFile
                Do While Not EOF(MyFile)
                   Line Input #MyFile, sNextLine
                   sNextLine = sNextLine & vbCrLf
                   sText = sText & sNextLine
                Loop
                Text1.Text = sText
                Close MyFile

                Then you need to read in the string and do your selection using the string manipulation functions which are posted here.

                http://www.thescripts.com/forum/thread781497.html
                I've got the same proplem. Does any one know how to post a request to a web page with an fixed URL, and get the content of this page into memory (or file).
                I know how to parse Strings from webpage content to get out dirsered infomation. But i need the content be loaded dirrectly from Internet

                Comment

                Working...