Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

I have a program that getting data from a web page, so I created a function that downloading its source(saving to text file). My problem is I cannot download the web page of LinkIn(This is the site that I'm getting the data at) but when I try downloading a sample web page(http://www.google.com.ph/), I can download it successfully. Don't know whats the error in this.

This is a sample web page:
http://www.linkedin.com/skills/skill/iPhone


VB
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
Private Declare Function InternetOpen Lib "wininet" 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 InternetCloseHandle Lib "wininet" (ByVal hInet As Long) As Integer

Public Function InternetGetFile(sURLFileName As String, sSaveToFile As String, Optional bOverwriteExisting As Boolean = False) As Boolean    
    Dim lRet As Long
    Const S_OK As Long = 0, E_OUTOFMEMORY = &H8007000E
    Const INTERNET_OPEN_TYPE_PRECONFIG = 0, INTERNET_FLAG_EXISTING_CONNECT = &H20000000
    Const INTERNET_OPEN_TYPE_DIRECT = 1, INTERNET_OPEN_TYPE_PROXY = 3
    Const INTERNET_FLAG_RELOAD = &H80000000

    On Error Resume Next
    'Create an internet connection
    lRet = InternetOpen("", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)

    If bOverwriteExisting Then
        If Len(Dir$(sSaveToFile)) Then
            VBA.Kill sSaveToFile
        End If
    End If
    'Check file doesn't already exist
    If Len(Dir$(sSaveToFile)) = 0 Then
        'Download file
        lRet = URLDownloadToFile(0&, sURLFileName, sSaveToFile, 0&, 0)
        If Len(Dir$(sSaveToFile)) Then
            'File successfully downloaded
            InternetGetFile = True
        Else
            'Failed to download file
            If lRet = E_OUTOFMEMORY Then
                'Debug.Print "The buffer length is invalid or there was insufficient memory to complete the operation."
                MsgBox "The buffer length is invalid or there was insufficient memory to complete the operation.", vbCritical + vbOKOnly, "Error while Downloading"
                End
            Else
                'Debug.Assert False
                'Debug.Print "Error occurred " & lRet & " (this is probably a proxy server error)."
                MsgBox "Error occurred " & lRet & " (this is probably a proxy server error).", vbCritical + vbOKOnly, "Error while Downloading"
                End
            End If
            InternetGetFile = False
        End If
    End If
    On Error GoTo 0

End Function

Public Sub Download(ByVal url As String, ByVal location As String)
    InternetGetFile url, location, True
    'If InternetGetFile(URL, location, True) Then
    '    MsgBox "Successfully downloaded file!"
    'Else
    '    MsgBox "Failed to download file!"
    'End If
End Sub
Posted
Updated 13-Sep-11 22:39pm
v2
Comments
CPallini 14-Sep-11 5:06am    
What about 'debugging'?
hansoctantan 14-Sep-11 6:44am    
I really don't know why this happens, I try downloading the url in this web page and it works fine.
thatraja 9-Dec-11 1:47am    
What's the error message?
hansoctantan 9-Dec-11 4:07am    
the program execute this MsgBox "Error occurred " & lRet & " (this is probably a proxy server error).", vbCritical + vbOKOnly, "Error while Downloading"
thatraja 9-Dec-11 5:31am    
No, what's the actual error message? Use Error.Number & Error.Message to get actual error

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900