原创的一段通过XML来远程抓娶图片的代码

 1   
 2'函数1调用XSMXL2.XMLHTTP来进行远程抓取   
 3function getHTTPPage(url)   
 4on error resume next   
 5dim http   
 6set http=server.createobject("MSXML2.XMLHTTP")'使用xmlhttp的方法来获得图片的内容   
 7Http.open "GET",url,false   
 8Http.send()   
 9if Http.readystate<>4 then   
10exit function   
11end if   
12getHTTPPage=Http.responseBody   
13set http=nothing   
14if err.number<>0 then err.Clear   
15end function   
16'函数2 对数据进行保存   
17function img(from,tofile)   
18dim geturl,objStream,imgs   
19geturl=trim(from)   
20imgs=gethttppage(geturl)   
21Set objStream = Server.CreateObject("ADODB.Stream")   
22objStream.Type =1   
23objStream.Open   
24objstream.write imgs   
25objstream.SaveToFile server.mappath(tofile),2   
26objstream.Close()   
27set objstream=nothing   
28end function   

<%=img (" http://stock.jrj.com.cn/htmdata/gifindex/Sh_000001.png","sh1.png")% >

1<img src="Sh1.png"/>

<%=img (" http://stock.jrj.com.cn/htmdata/gifindex/sz_399001.png","sh2.png")% >

1<img src="Sh2.png"/>

<%=img (" http://business.sohu.com/new_world_index.html","gjgshq.html")% >

1<iframe frameborder="0" height="140" name="a" scrolling="auto" src="gjgshq.html" width="160"></iframe>
Published At
Categories with Web编程
Tagged with
comments powered by Disqus