SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How do I read an external page?

    I'm no ASP/VBScript guru, but I need to read a page from another domain, extract some information, and format it inside one of our own pages at the office.

    Just to make one thing clear: I'm not ripping off someone else's page. The external site handles employment ads, and we're supposed to include our own ads from there. Frames or iframes are out of the question, since we use HTML 4.01 Strict. The markup on the external page is horrible (layout tables, presentational markup, etc.).

    I want to read the external page into a string, and then extract the actual ad information and format that on our page. This would be very easy in PHP, using fopen(), and I assume there is something similar for ASP/VBScript.

    Any help would be greatly appreciated.
    Birnam wood is come to Dunsinane

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Why don't you use XMLHTTPRequest, what you do is call the page, you can then set the responseText as a variable and then use replace, and reg expressions to edit and configure the output.

    Code:
      <%
       Response.Buffer = True
       Dim objXMLHTTP, xml
     
       Set xml = Server.CreateObject("Microsoft.XMLHTTP")
    	  xml.Open "GET", "http://www.4Guysfromrolla.com/", False
    	  xml.Send
     
     Dim Output
     	  Output = xml.responseText
     
     Output = Replace(Output,"original","replacement")
     
     Response.write(Output)
      
       Set xml = Nothing
     %>
    You can remove the Response.write and use that variable anywhere in the page. Just change the address ( i'm at work otherwise I would of posted my own personal code ) from http://www.4guysfromrolla.com to what ever the page is you want to emulate.

    Kind regards

    Gav


  3. #3
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was under the impression that XMLHttpRequest could not be used for sending requests across domains. If I'm wrong, that solves the problem!

    Thanks.
    Birnam wood is come to Dunsinane

  4. #4
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    From the above, you never mentioned sending info, but this shouldn't be an issue, change GET to POST and provide the querystring variables and as long as the receiving page has the same variable requests, then great.

    Posting data across domins isn't an issue, look at paypal? You send data via form across to their payment system. Although I'm not sure whether it's been done, but you should be able to use POST to send details to paypal then use asp to change the page to suit your design, but SSL would cause an issue?

    Gav


  5. #5
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep. I just tried this and it worked like a charm! I'm extracting the data from their hideous table soup and formatting it as a clean DL instead. There's no need to POST anything; it's just a simple GET request.

    Next time I'll try for myself rather than believe someone who says it can't be done.

    Thank you ever so much for your help!
    Birnam wood is come to Dunsinane

  6. #6
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Theres no harm in asking, you don't ask you don't know. Although Trial and Error I find is the best way to learn.

    Glad I could help my friend, do you get the just of the Replace to format the page?

    Gav


  7. #7
    SitePoint Author silver trophybronze trophy

    Join Date
    Nov 2004
    Location
    Ankh-Morpork
    Posts
    12,159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't use Replace, because there's too much junk that needs to be removed. Fortunately, the page has a simple structure (a table with two columns and a varying number of rows (varying between calls that is )). So I can use InStr and Mid to extract the values. One column is just a date, so that's no problem. The other one is a link where I extract the HREF and the content, plus the TITLE where they store the job description.
    Birnam wood is come to Dunsinane

  8. #8
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ah right.. Well you could always use regular expressions. If not the way you know of doing it is always the best.

    Gav



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •