Rafael Nascimento
New Member
- Joined
- Jan 21, 2018
- Messages
- 1
Hello guys!
I am facing an specifc issue here, I am trying to acess the Airbnb webpage, and then download a CSV file with the historical transactions/reservations.
The interesting thing is that when I use the API function URLDownloadToFile in my code, the CSV file comes filled with a lot of code (HTML).
However, when I click on the link "Export CSV" in the webpage, the file's content comes ok with the right information.
I am searching for information, and until now I didn't get anything.
I would be very thankful for any help! (Sorry for my poor english)
Bellow follows my code with comments.
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As LongPtr, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As LongPtr, _
ByVal lpfnCB As LongPtr) As LongPtr
#Else
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
#End If
Sub BrowseToAirbnb_Wastolfi()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLPage As MSHTML.HTMLDocument
Dim Year As Integer
Dim strURL As String
Dim LocalFilePath As String
Dim DownloadStatus As Long
Dim File_name As String
File_name = Range("User").Value
Year = Range("Selection_year").Value
IE.Visible = True
IE.navigate "www.airbnb.com/users/transaction_history"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Debug.Print IE.LocationName, IE.LocationURL
Set HTMLDoc = IE.document
HTMLDoc.all.Email.Value = "xxxx@yyyyyy" ' Login
HTMLDoc.all.Password.Value = "zzzzzzz" 'Password
Set HTMLInput = HTMLDoc.getElementById("user-login-btn")
HTMLInput.Click ' Clicking on the button ENTER
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Application.Wait (Now + TimeValue("0:00:10"))
strURL = "https://www.airbnb.com.br/transaction_history/csv/ccccccccccfor_payout_tracker=true&year=" & Year & "&start_month=1&end_month=12&page=1"
LocalFilePath = "C:\Users\Administrador\Desktop\Test" & File_name & ".csv"
DownloadStatus = URLDownloadToFile(0, strURL, LocalFilePath, 0, 0)
If DownloadStatus = 0 Then
MsgBox "File Downloaded. Check in this path: " & LocalFilePath
Else
MsgBox "Download File Process Failed"
End If
End Sub
I am facing an specifc issue here, I am trying to acess the Airbnb webpage, and then download a CSV file with the historical transactions/reservations.
The interesting thing is that when I use the API function URLDownloadToFile in my code, the CSV file comes filled with a lot of code (HTML).
However, when I click on the link "Export CSV" in the webpage, the file's content comes ok with the right information.
I am searching for information, and until now I didn't get anything.
I would be very thankful for any help! (Sorry for my poor english)
Bellow follows my code with comments.
Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
ByVal pCaller As LongPtr, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As LongPtr, _
ByVal lpfnCB As LongPtr) As LongPtr
#Else
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
#End If
Sub BrowseToAirbnb_Wastolfi()
Dim IE As New SHDocVw.InternetExplorer
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLInput As MSHTML.IHTMLElement
Dim HTMLPage As MSHTML.HTMLDocument
Dim Year As Integer
Dim strURL As String
Dim LocalFilePath As String
Dim DownloadStatus As Long
Dim File_name As String
File_name = Range("User").Value
Year = Range("Selection_year").Value
IE.Visible = True
IE.navigate "www.airbnb.com/users/transaction_history"
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Debug.Print IE.LocationName, IE.LocationURL
Set HTMLDoc = IE.document
HTMLDoc.all.Email.Value = "xxxx@yyyyyy" ' Login
HTMLDoc.all.Password.Value = "zzzzzzz" 'Password
Set HTMLInput = HTMLDoc.getElementById("user-login-btn")
HTMLInput.Click ' Clicking on the button ENTER
Do While IE.readyState <> READYSTATE_COMPLETE
Loop
Application.Wait (Now + TimeValue("0:00:10"))
strURL = "https://www.airbnb.com.br/transaction_history/csv/ccccccccccfor_payout_tracker=true&year=" & Year & "&start_month=1&end_month=12&page=1"
LocalFilePath = "C:\Users\Administrador\Desktop\Test" & File_name & ".csv"
DownloadStatus = URLDownloadToFile(0, strURL, LocalFilePath, 0, 0)
If DownloadStatus = 0 Then
MsgBox "File Downloaded. Check in this path: " & LocalFilePath
Else
MsgBox "Download File Process Failed"
End If
End Sub