Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Handling Live Web Content in WSH - Part 1
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Handling Live Web Content in WSH - Part 1
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 10
    2006-09-06

    Table of Contents:
  • Handling Live Web Content in WSH - Part 1
  • Processing the Response
  • A Little Error-Handling
  • The Final Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Handling Live Web Content in WSH - Part 1 - Processing the Response


    (Page 2 of 4 )

    We begin processing the html response by setting up an If statement.  Basically, we’re just going to make sure that our variable actually holds some data before we try to play with it.  If it doesn’t, that means that there was an error connecting to the site.

    If strHTMLText <> "" Then

       varStart = inStr(1, strHTMLText, "Current IP Address:", _

           vbTextCompare) + 19

       If varStart Then varStop = inStr(varStart, strHTMLText, "</body>", _

           vbTextCompare)

       If varStart And varStop Then strIP = mid(strHTMLText, varStart, _

           varStop - varStart)

    Okay, our first line checks to makes sure that the strHTMLText variable is not empty.  If it isn’t, then we begin processing it.  The second line uses the VB inStr() function.  The inStr() function will match our search parameter within a given string and return an integer indicating the starting character where our search criteria appears within that string.  So we look at the source code and pick a unique string that appears before our IP address.  In this case we’ve chosen “Current IP Address:”.  The inStr() function will return the position of the first character is finds in the matching string, so we add 19 (the number of characters in our search string) to be sure that it returns the value just before our IP address.

    The ideal way to do this would be to use our IP address as the search string, but since we don’t know what it is, this is a viable workaround.  We could also use regular expressions by using the RegExp object, but that’s a little more difficult, and it also adds quite a bit of extra code.

    In the third line we go back to the inStr() function to find the starting character after our IP address.  So again, we check the source code and find a unique search string.  This time inStr() will return the correct value so we don’t need to adjust it.  We’ll assign this to the variable varStop.

    Now that we’ve narrowed down the information that we want, our next goal is to remove all of the extra text from our string.  We do this in the fourth line by implementing VB’s mid() function to cut one string from the middle of another.  Essentially, it performs a left trim and a right trim at the same time using the values that we specify.  We assign the results of the mid() function to a string variable strIP.  If all went well strIP should contain only our IP address.

    More Windows Scripting Articles
    More By Nilpo


       · I wanted this article to demonstrate some alternative uses for WSH. A lot of people...
     

    WINDOWS SCRIPTING ARTICLES

    - A Portable Scripting Toolbox
    - WPF Through an Example: Introduction
    - Beginning SharePoint Web Part Development
    - More Alternative Languages for WSH
    - WPF Control Layout
    - WSH in Other Languages
    - Screen Capturing via GDI+ and GDI
    - Understanding Procedures in VBScript
    - Printing Documents in WSH
    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway