ASP
  Home arrow ASP arrow Page 3 - Getting Remote Pages with ASP
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
ASP

Getting Remote Pages with ASP
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 46
    2004-05-10

    Table of Contents:
  • Getting Remote Pages with ASP
  • Let's Code
  • A Little Parse-ly on the Side
  • Clean Up After Yourself!

  • 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


    Getting Remote Pages with ASP - A Little Parse-ly on the Side


    (Page 3 of 4 )

    You may just need to save the file locally, and nothing more. If that's the case, feel free to skip right to the clean-up section. But most likely you'll need to do some work on the file now that we have it.

    I'm going to show you how I read the file line-by-line, looking for indicators of specific columns of information. Looking back, I would for sure use regular expressions to do this searching were I to re-write the script. If you're only looking for a couple of items, this is one way to tackle it, but for anything more I would highly recommend using a regular expression.

    If Not objFSO.FileExists("csv.txt") Then objFSO.CreateTextFile("csv.txt")
    Set objFile  = objFSO.GetFile("csv.txt")
    Set objWrite = objFile.OpenAsTextStream( 2, -2 )
    Set objFile2 = objFSO.GetFile("skaters.txt")
    Set objRead  = objFile2.OpenAsTextStream( 1, -2 )

    So we've opened the file for reading, and created a file to retain the extracted data in comma separated values. Now we just need to define exactly what we want. I had it easy because the columns of data that I wanted to start with all had a similar class. So I just skipped through all the content in the head and body of the web page that occurred before the data and then started my work. You may have to examine the downloaded file and figure out your own plan of attack.

    strSearch = "<tr class=""ysprow"
    thisLine = ""
    dim firstName, lastName, pts
     
    Do Until Left(thisLine, Len(strSearch)) = strSearch And Not objRead.AtEndOfStream
    thisLine = objRead.ReadLine
    Loop

    Now I do the extraction of the first name, last name, and points. This could be somewhat problematic if the information you seek is not in such a well defined format. But mine was, so here's how I did it:

    While Not objRead.AtEndOfStream
     If Left(thisLine, Len(strSearch)) = strSearch Then '=== name
      thisLine = objRead.ReadLine
      '=== trimming
      thisLine = Mid(thisLine, InStr(thisLine, "<a"))
      thisLine = Mid(thisLine, InStr(thisLine, """>") + 2)
      thisLine = Left(thisLine, InStr(thisLine, "</a>") -1)
      '=== extract first name
      firstName = Left(thisLine, InStr(thisLine, " ") -1)
      '=== extract last name
      lastName = Right(thisLine, len(thisLine) - Len(firstName) - 1)
     End If
     '=== now search for points column
     If InStr(thisLine, "td class=""ysptblclbg6""") > 0 Then 'points
      '=== trim
      thisLine = Mid(thisLine, InStr(thisLine, "<span class=""yspscores"">") + 24)
      thisLine = Left(thisLine, InStr(thisLine,"<") - 1)
      '=== extract points
      pts = thisLine
      objWrite.WriteLine( firstName & "," & lastName & "," & pts )
     End if
     thisLine = objRead.ReadLine
    Wend

    objRead.Close

    More ASP Articles
    More By Justin Cook


     

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT