经典ASP:在外部网站上抓取图片网址

时间:2014-05-05 21:59:26

标签: vbscript asp-classic

在Classic ASP中,我需要获取外部网站并获取所有图片网址,以便能够创建缩略图目录。

有没有人有一些脚本让我入门?

2 个答案:

答案 0 :(得分:1)

这是我的解决方案。它绝对可以清洁和收紧,但它确实有效:

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

答案 1 :(得分:0)