Question

In Classic ASP, I need to fetch an external website and grab all the image urls to be able to create a thumbnail directory.

Does anyone have some script to get me started?

Was it helpful?

Solution

Here is my solution. It could definitely be cleaned and tightened, but it works:

remoteurl = "http://news.yahoo.com"

Set http = CreateObject("MSXML2.ServerXMLHTTP.6.0")
http.Open "GET", remoteurl, False
http.Send

Set re = New RegExp
re.Pattern = " ]*src=[""'][^ >]*(jpg|png)[""']"
re.IgnoreCase = True
re.Global = True
re.Multiline = True
Set oMatches = re.Execute(http.responseText)
If Not oMatches Is Nothing Then
    If oMatches.Count > 0 Then
    For Each oMatch In oMatches
        If Not oMatches(0).SubMatches Is Nothing Then
            sBodyText = oMatch.value
            sBodyText = replace(sBodyText,"src=""","")
            sBodyText = replace(sBodyText,"""","")
            response.write "<img src="""&sBodyText&""" style=""max-height:10px;""/><br />"
        End If
    Next
    End If
End If
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top