ASP download the picture instance in the webpage

Source: Internet
Author: User
Web page | Download

<%


Function Replaceremoteurl (SHTML, Ssavefilepath, Sfileext)


'//


'//remote save Picture


'/////////////////////////////////////////////////////


' role: Replace the remote file in the string with a local file and save the remote file


' parameter:


' SHTML: string to replace


' Ssavepath: path to save file


' sExt: The extension that performs the replacement


Dim s_content


s_content = SHTML


' If isobjinstalled ("microsoft.xmlhttp") = False then


' Replaceremoteurl = s_content


' Exit Function


' End If


' Remote picture save directory, end please do not add "/"


savefilepath= "/upload"


' remote picture Save type


fileext= "Jpg|gif|bmp|png"


Dim Re, remotefile, Remotefileurl,savefilename,savefiletype,arrsavefilenames,arrsavefilename,ssavefilepaths


Set re = new REGEXP


Re. IgnoreCase = True


Re. Global = True


Re. Pattern = "((HTTP|HTTPS|FTP|RTSP|MMS):(\/\/|\\\\) {1} ((\w) +[.]) {1,} (net|com|cn|org|cc|tv| [0-9] {1,3}) (\s*\/) ((\s) +[.] {1} ("& Sfileext &")) "


' s_content= "sicon.gif sfsdf"


Response.Write S_content


Set remotefile = Re. Execute (s_content)


for each remotefileurl in RemoteFile


savefiletype = replace (replace (Remotefileurl, "/", "a"), ":", "a")


' Arrsavefilename = Right (savefiletype,12)


Arrsavefilename = Mid (Remotefileurl,instrrev (Remotefileurl, "/") +1)


Ssavefilepaths=ssavefilepath & "/"


savefilename = ssavefilepaths & Arrsavefilename


Call Saveremotefile (Savefilename, Remotefileurl)


s_content = Replace (s_content,remotefileurl,savefilename)


Next


Replaceremoteurl = s_content


End Function

Sub saveremotefile (localfilename,remotefileurl)
    Dim Ads, retrieval, Getremotedata
    on Error Resume Next
    Set retrieval = Server.CreateObject ("Microsoft.XMLHTTP")
    with Retrieval
       . Open "Get", Remotefileurl, False, "", "
       . Send
        getremotedata =. Responsebody
    End with
    set retrieval = Nothing
    set Ads = Server.CreateObject ("ADODB.stream")
    with Ads
        . Type = 1
       . Open
       . Write getremotedata
       . SaveToFile Server.MapPath (LocalFilename), 2
       . Cancel ()
       . Close ()
    end with
    Set ads=nothing
End Sub

server.scripttimeout=6000 ' page timeout
Url= "http://www.webjx.com/htmldata/2006-02-20/1140402873.html" ' Received URL
Code=replace (gethttppage (URL), vbCrLf, "") replaces the return character in the code

start=instr (Code, "<html>") ' starts with the codes here to start with a unique code in the Web page


over=instr (Code, "</html>") ' The end of the codes here is the unique code end of the page


types=mid (code,start,over-start) ' Types variable is the part you need


'//This should continue to be done after the acquired code to meet your needs


'//I took it from <html> to </html> so I read the whole page actually according to my own need to check the code of others


'//actually need some other functions, such as the function of organizing HTML markers, and automatically receiving functions of remote pictures


'//There is the automatic page jump and so on = = This is to see their own expansion


Types=replaceremoteurl (types,savefilepath,fileext)/download remote picture


Response.Write Types ' test output


' functions below the tube, including open, read, Web


Function gethttppage (Path)


t = getbody (Path)


gethttppage=bytestobstr (T, "GB2312")


End Function


Function getbody (URL)


On Error Resume Next


Set retrieval = CreateObject ("Microsoft.XMLHTTP")


with Retrieval


        . Open "Get", url, False, "", ""


        . Send


getbody =. Responsebody


End With


Set retrieval = Nothing


End Function


Function bytestobstr (body,cset)


Dim objstream


Set objstream = Server.CreateObject ("ADODB.stream")


Objstream. Type = 1


objstream. Mode = 3


objstream. Open


objstream. Write Body


objstream. Position = 0


objstream. Type = 2


objstream. Charset = Cset


bytestobstr = objstream. ReadText


objstream. Close


Set objstream = Nothing


End Function


%>







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.