|
楼主 |
发表于 2009-12-12 08:41
|
显示全部楼层
用URLDownloadToFile函数的代码。- Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
- Public Function DownloadFile(URL As String, LocalFilename As String) As Boolean
- Dim lngRetVal As Long
- lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
- If lngRetVal = 0 Then DownloadFile = True
- End Function
- Sub cc()
- Dim s() As String, r%, i&, j&
- IName = "刘亦菲"
- Path = ThisWorkbook.Path & ""
- MkDir Path & IName
- On Error Resume Next
- With CreateObject("Msxml2.XMLHTTP")
- For r = 0 To 100 Step 20
- .Open "GET", "http://images.google.cn/images?gbv=2&hl=zh-CN&newwindow=1&q=" & IName & "&sa=N&start=" & r & "&ndsp=20"", true"
- .Send
- Do Until .ReadyState = 4
- DoEvents
- Loop
- s = Split(.responseText, """")
- For i = 0 To UBound(s)
- If s(i) Like "http://*" Then
- If InStr(s(i), "jpg") Then
- j = j + 1
- DownloadFile s(i), Path & IName & "" & j & ".jpg"
- End If
- End If
- Next
- Next
- End With
- End Sub
复制代码 |
|