1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Private Const INTERNET_OPEN_TYPE_PRECONFIG As Long = &H0
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Public Function DownloadSource(ByVal Url As String, ByVal UserAgent As String) As String
Dim hOpen As Long
Dim hOpenUrl As Long
Dim sReadBuffer As String * 1024
Dim lNumberOfBytesRead As Long
Dim sBuffer As String
hOpen = InternetOpen(UserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
hOpenUrl = InternetOpenUrl(hOpen, Url, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
Do
sReadBuffer = vbNullString
Call InternetReadFile(hOpenUrl, sReadBuffer, Len(sReadBuffer), lNumberOfBytesRead)
sBuffer = sBuffer & Left$(sReadBuffer, lNumberOfBytesRead)
DoEvents
Loop While lNumberOfBytesRead > 0
If Not hOpenUrl = 0 Then Call InternetCloseHandle(hOpenUrl)
If Not hOpen = 0 Then Call InternetCloseHandle(hOpen)
DownloadSource = sBuffer
End Function |
Partager