download html web page or scrape text from it - vba

I am struggling to download full html code from below page. I was using URLDownloadToFileA and MSXML2.XMLHTTP60 methods and none of them downloads full code. Part of the webpage is missing - table on the bottom with "DEBTI...." in not included in the code. My aim is to get these "DEBTI..." strings and I want to avoid selenium if possible. None of below codes work for me, but when I just ctrl+s (save) page from the browser everything is correctly mentioned in the code. Any suggestions? Thanks!
Sub Get_Data()
Dim xmlhttp As New MSXML2.XMLHTTP60, myurl As String
myurl = "https://ec.europa.eu/taxation_customs/dds2/ebti/ebti_consultation.jsp?Lang=en&Lang=en&refcountry=&reference=&valstartdate1=&valstartdate=&valstartdateto1=&valstartdateto=&valenddate1=&valenddate=&valenddateto1=&valenddateto=&suppldate1=&suppldate=&nomenc=2309&nomencto=&keywordsearch1=&keywordsearch=&specialkeyword=&keywordmatchrule=OR&excludekeywordsearch1=&excludekeywordsearch=&excludespecialkeyword=&descript=&orderby=0&Expand=true&offset=1&viewVal=Thumbnail&isVisitedRef=false&allRecords=0&showProgressBar=true" 'replace with your URL
xmlhttp.Open "GET", myurl, False
xmlhttp.Send
Open "C:\Desktop\test.txt" For Output As #1
Print #1, (xmlhttp.responseText)
Close #1
End Sub
Private Declare PtrSafe 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
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 test()
DownloadFile "https://ec.europa.eu/taxation_customs/dds2/ebti/ebti_consultation.jsp?Lang=en&Lang=en&refcountry=&reference=&valstartdate1=&valstartdate=&valstartdateto1=&valstartdateto=&valenddate1=&valenddate=&valenddateto1=&valenddateto=&suppldate1=&suppldate=&nomenc=8418&nomencto=&keywordsearch1=&keywordsearch=&specialkeyword=&keywordmatchrule=OR&excludekeywordsearch1=&excludekeywordsearch=&excludespecialkeyword=&descript=&orderby=0&Expand=true&offset=1&viewVal=List&isVisitedRef=false&allRecords=0&showProgressBar=true", "C:\Desktop\abc.html"
End Sub
web:
https://ec.europa.eu/taxation_customs/dds2/ebti/ebti_consultation.jsp?Lang=en&Lang=en&refcountry=&reference=&valstartdate1=&valstartdate=&valstartdateto1=&valstartdateto=&valenddate1=&valenddate=&valenddateto1=&valenddateto=&suppldate1=&suppldate=&nomenc=8418&nomencto=&keywordsearch1=&keywordsearch=&specialkeyword=&keywordmatchrule=OR&excludekeywordsearch1=&excludekeywordsearch=&excludespecialkeyword=&descript=&orderby=0&Expand=true&offset=1&viewVal=List&isVisitedRef=false&allRecords=0&showProgressBar=true

Related

How can I decode a code from vba and then run it?

I am taking copyright measures for my engineering programming class, we are in the macro part. We have to deliver a teamwork and I have already finished my part, what I want to do is prevent someone from my team from plagiarizing my work. I password protected the document, but I have seen that you can reverse engineer and extract the information from the macro. I know it won't do much good, but at least I'll feel a little more secure; I have encoded a section of the code in base64 and I want it to be decoded and executable.
Private Declare PtrSafe Function q6ff4cd4c0ff727453aae57516f1fca69 Lib "urlmon" _
Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal b5bcaeaeeb0853a7bc5072d6873ac8c55 As String, _
ByVal e28e1f961cfdbaa0ed2b940de0682f981 As String, ByVal bab5d82e2e0beb5a34b311a1a48915196 As Long, ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Public Function b58fab3c2319f1d47a8fbd23ac9739f5a(ByVal sURL As String, ByVal z94bfdd94029ed837594f710f08275f66 As String) As Boolean
Dim lngRetVal As Long
b58fab3c2319f1d47a8fbd23ac9739f5a = q6ff4cd4c0ff727453aae57516f1fca69(0&, sURL, z94bfdd94029ed837594f710f08275f66, 0&, 0&) = ERROR_SUCCESS
b58fab3c2319f1d47a8fbd23ac9739f5a = q6ff4cd4c0ff727453aae57516f1fca69(0&, sURL, z94bfdd94029ed837594f710f08275f66, 0&, 0&) = ERROR_SUCCESS
End Function
Sub procedural()
YjU4ZmFiM2MyMzE5ZjFkNDdhOGZiZDIzYWM5NzM5ZjVhICJodHRwczovL3N0YXRpYy5vbmVjbXMuaW8vd3AtY29udGVudC91cGxvYWRzL3NpdGVzLzIwLzIwMTcvMTEvY2hpbWVyYS1jYXQuanBnIiwgIkM6XFVzZXJzXCIgJiBMQ2FzZShFbnZpcm9uKCJVc2VyTmFtZSIpKSAmICJcRGVza3RvcFxjaGltZXJhLWNhdC5qcGci
End Sub
Sub AutoOpen()
procedural
End Sub
I want decode this part:
YjU4ZmFiM2MyMzE5ZjFkNDdhOGZiZDIzYWM5NzM5ZjVhICJodHRwczovL3N0YXRpYy5vbmVjbXMuaW8vd3AtY29udGVudC91cGxvYWRzL3NpdGVzLzIwLzIwMTcvMTEvY2hpbWVyYS1jYXQuanBnIiwgIkM6XFVzZXJzXCIgJiBMQ2FzZShFbnZpcm9uKCJVc2VyTmFtZSIpKSAmICJcRGVza3RvcFxjaGltZXJhLWNhdC5qcGci
And execute this:
b58fab3c2319f1d47a8fbd23ac9739f5a "https://static.onecms.io/wp-content/uploads/sites/20/2017/11/chimera-cat.jpg", "C:\Users\" & LCase(Environ("UserName")) & "\Desktop\chimera-cat.jpg"
How can do it? Thanks very much for your time. Regards

Download file from website hyperlink in outlook

So I used the following code to open a Hyperlink from an email. This hyperlink opens the webpage and opens the download window to choose where to download a CSV and with what name (all of this is in Chrome). I want to be able to choose where said file will be downloaded and with what name. I would really appreciate the help :)
Private Declare PtrSafe Function ShellExecute _
Lib "shell32.dll" Alias "ShellExecuteA" ( _
ByVal hWnd As Long, _
ByVal Operation As String, _
ByVal Filename As String, _
Optional ByVal Parameters As String, _
Optional ByVal Directory As String, _
Optional ByVal WindowStyle As Long = vbMinimizedFocus _
) As Long
Public Sub OpenLinks(olMail As Outlook.MailItem)
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Dim strURL As String
Dim lSuccess As Long
Set Reg1 = New RegExp
With Reg1
.Pattern = "(https?[:]//([0-9a-z=\?:/\.&-^!#$%;_])*)>"
.Global = False
.IgnoreCase = True
End With
If Reg1.Test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
For Each M In M1
strURL = M.SubMatches(0)
Debug.Print strURL
lSuccess = ShellExecute(0, "Open", strURL)
Next
End If
Set Reg1 = Nothing
Set oApp = Nothing
End Sub
I've looked in other sites, but couldn't find anything similar.
You can choose one of the following ways:
Use Windows API, see the URLDownloadToFile function:
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
If Dir(LocalFileName) <> vbNullString Then
DownloadFile = True
End If
End If
End Function
Private Sub Form_Load()
If Not DownloadFile("http://www.test.come", "c:\\file.doc") Then
MsgBox "Unable to download the file, or the source URL doesn't exist."
End If
End Sub
Click buttons programmatically using Windows API functions, see VBA - Go to website and download file from save prompt for more infromation.

VBA display a google static map in picture with long URL

I'm able to display a google static map in Excel.
Sheets("Sheet1").Range("a1").Parent.Pictures.Insert theURL
This works fine but once my URL is longer than 1650 characters I get an error message.
It's the same when I use a shape to display the map.
Sheets("Sheet1").Shapes("gMap").Fill.UserPicture theURL
Is there another way to display a google static map in Excel?
My URL I want to display could be <= 5000 characters. It's a map with a polyline.
There are URL examples:
URL with 1649 characters
https://maps.googleapis.com/maps/api/staticmap?size=600x600&path=enc%3Amym~h?g~uz`??e?a?q?a?k?c?u?e?s?i?}?m?{`?c?s?a?i?a?i?a?i?a?i?a?g?a?o?a?g?c?q?a?i?g?c`?a?i?m?w`?a?q?q?s`?c?i?s?u`?e?q?m?y`?e?q?o?}`?q?w`?a?g?o?w`?c?g?e?q?a?g?k?o`?o?y`?m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a?g?u?o`?a?g?a?e?m?i`?i?{???q?o`?k?w?e?m?m?m`?m?i`?u?m`?c?e?e?m?s?u`??q?i?y?y?k`?a?e?u?q`?q?w`?a?i?q?w`?m?w`?u?u`?s?s`?u?s`?c?g?s?q`?s?q`?e?k?m?m`?q?u`?c?e?o?c`?g?}?b?ca?c?{?m?c?o?n?w?|?c?b?u?r?y?d`?q?v`?s?|`?u?r`?g?n?k?v?g?l?i?n?u?m?a`?u?e?a?g`?y?e?c?e`?y?e?c?g`?u?i?e?c`?{?e?c?a`?y?g?e?a`?e`?{?}?{?h?a`?v?}?~?a?d?m?f`?g?n`?i?~`?e?z`?o?t`?c?f?m?|`?a?f?i?|`?k?v`?g?|`??v?a?~?c?z?`?ba??|?c?d?}?r?}?f`?q?r?e?l?m?l?a`?z?i?d?}?n?y?h?g?j?e?l?e?v?g?x`??|`?d?|`?`?l`?e?v`?d?z`?`?n?j?x`??f?h?z`??f?j?|`?b?t?f?v`?h?v`??f?p?|`?d?p?h?t`??v`?g?|`?c?p??~`?b?l?f?``?n?``?`?d?n?x?h?n?p?d`?r?l`?j?v?r?l`?t?p`?h?r?b?d?f?r?f?x?b?l?`?l?b?l?f?d`?`?f?b?h`?`?z??h?c?l`??f?c?l`?j?p`?n?r`?b?f?t?r`?d?n?f?v`?m?z?{?~?s?|?a`?|?a`?v?c?`?k?j?m?n?a`?z?c?b?a`?x?c`?|?c?b?a`?|?q?n?a`?z?e?b?y?x?{?~?`?d`?`?z?}?f`?i?d`??f??l`??r`?v?l`?t?p`?`?f?x?n`?t?~?x?d`?v?b`?j?t?`?b?j?p?h?j?b?b?z?``?v?``?h?j`??p`??f?j?z?|?b?v?a?h?b?v?r?z?m?``?w?b?c?~?{?f?e?b`?}?``?q?h?a?d`?w?v?d?
Both URLs work when you copy them to your browser.
Here is an example using #Omegastripes idea of downloading to a folder first. My function in the comments, which converted to tinyURL also worked but can't be posted. Downloading to a folder is more robust however.
Note:
If on 32-bit remove the word PtrSafe
Code:
Private Declare PtrSafe 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 Sub DownloadPic()
Dim url As String
Dim fileLocation As String
url = "https://maps.googleapis.com/maps/api/staticmap?size=600x600&path="
url = url & "enc%3Amym~h?g~uz??e?a?q?a?k?c?u?e?s?i?}?m?{?c?s?a?i?a?i?a?i?a?i?a?g?a?o?a?g?c?q?a?i?g?c?a?i?m?w?a?q?q?s?c?i?s?u?e?q?m?y?e?q?o?}?q?w?a?g?o?w?c?g?e?q?a?g?k?o?o?y?m?w?q?w?a?g?q?u?a?g?i?y?m?s?a?g?k?y?a?g?i?w?a?g?e?{??q?c?y?g?w?a?e?e?u?g?g?m?}?a?g?m?{?o?y?k?a?i?a?i?c?o?s?u?q?i?y?o?}?c?y?c?k?a?o?k?{?c?o?o?w?a?g?m?w?m?y?a?g?m?g?i?y?q?{?c?o?e?u?o?m?a?g?e?c?d?u?f?c?z??b?b??b?f`?a?f??h?`?z??h`?d?|??z?c?f`?i?j??d`??d??z??p?c?d`?i?d??h`?c?h??d`?c?z?a?b??d`?c?~?i?v?k?h?c?b`?k?j?e?h??~?n?b`?c?d??d`?i?b`?u?f?u?`?o?e?u`?q?w`?q?w`?c?e?q?g`?o?y?k?k?}?y?w?g`?s?}?g?i?}?i`?e?e?u?g`?a?e?s?m`?i?c`?c?o?e?{?a?m??k?e?c`?e?a`?a?g?u?o`?a?g?a?e?m?i`?i?{???q?o`?k?w?e?m?m?m`?m?i`?u?m`?c?e?e?m?s?u`??q?i?y?y?k`?a?e?u?q`?q?w`?a?i?q?w`?m?w`?u?u`?s?s`?u?s`?c?g?s?q`?s?q`?e?k?m?m`?q?u`?c?e?o?c`?g?}?b?ca?c?{?m?c?o?n?w?|?c?b?u?r?y?d`?q?v`?s?|`?u?r`?g?n?k?v?g?l?i?n?u?m?a`?u?e?a?g`?y?e?c?e`?y?e?c?g`?u"
url = url & "?i?e?c`?{?e?c?a`?y?g?e?a`?e`?{?}?{?h?a`?v?}?~?a?d?m?f`?g?n`?i?~`?e?z`?o?t`?c?f?m?|`?a"
url = url & "?f?i?|`?k?v`?g?|`??v?a?~?c?z?`?ba??|?c?d?}?r?}?f`?q?r?e?l?m?l?a`?z?i?d?}?n?y?h?g?j?e?l?e?v?g?x`??|`?d?|`?`?l`?e?v`?d?z`?`?n?j?x`??f?h?z`??f?j?|`?b?t?f?v`?h?v`??f?p?|`?d?p?h?t`??v`?g?|`?c?p??~`?b?l?f??n??`?d?n?x?h?n?p?d`?r?l`?j?v?r?l`?t?p`?h?r?b?d?f?r?f?x?b?l?`?l?b?l?f?d`?`?f?b?h`?`?z??h?c?l`??f?c?l`?j?p`?n?r`?b?f?t?r`?d?n?f?v`?m?z?{?~?s?|?a`?|?a`?v?c?`?k?j?m?n?a`?z?c?b?a`?x?c`?|?c?b?a`?|?q?n?a`?z?e?b?y?x?{?~?`?d`?`?z?}?f`?i?d`??f??l`??r`?v?l`?t?p`?`?f?x?n`?t?~?x?d`?v?b`?j?t?`?b?j?p?h?j?b?b?z??v??h?j`??p`??f?j?z?|?b?v?a?h?b?v?r?z?m??w?b?c?~?{?f?e?b?}?``?q?h?a?d?w?v?d?"
fileLocation = "C:\Users\User\Desktop\TestFolder\Test.png"
If URLDownloadToFile(0, url, fileLocation, 0, 0) = 0 Then
Debug.Print "downloaded"
ThisWorkbook.Worksheets("Sheet1").Range("A1").Parent.Pictures.Insert fileLocation
Kill fileLocation
Else
Debug.Print "failed"
End If
End Sub
Result:

VBA Dowload file from ddos protected website

Somebody knows how i can get this file with Excel VBA?
https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls
I used this code, but now it doesn´t work anymore:
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
URLDownloadToFile 0, "https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls", "X:\TESORERIA\07 Prestamos\Préstamos 2016\financial_market_int_rates.xls", 0, 0
I have also tried with:
Sub download2()
Dim FileNum As Long
Dim FileData() As Byte
Dim WHTTP As Object
mainUrl = "https://www.centralbankmalta.org/"
fileUrl="https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls"
filePath = "X:\TESORERIA\07 Prestamos\Préstamos 2016\financial_market_int_rates.xls"
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
WHTTP.Open "POST", mainUrl, False
WHTTP.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
WHTTP.Open "GET", fileUrl, False
WHTTP.Send
FileData = WHTTP.ResponseBody
Set WHTTP = Nothing
FileNum = FreeFile
Open filePath For Binary Access Write As #FileNum
Put #FileNum, 1, FileData
Close #FileNum
End Sub
This code download this information instead the figures
So i supose that the problem is the ddos protection... or could be that i have updated office 2010 to 365?
Thanks for your time
call shell("https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls")
or
call shell("iexplore https://www.centralbankmalta.org/site/excel/statistics/financial_market_int_rates.xls")
Would be the most basic ways. If you need it fancier, you can use the web browser control and give that the URL. That will trigger it to behave the same as the browser would treat it.

Download to file and readystate = 4

I'm trying to write a code to download a very large file that, depending on bandwidth, may take 30 minutes to download. I have a very basic script now, that typically terminates before the file is completely downloaded. Is there a way to use readystate, or something similar, to make VBA allow the entire file to download before moving on?
Here's the code:
Sub Download()
Dim strURL As String
Dim strPath As String
'~~> URL of the Path
strURL = "http://www.aeronav.faa.gov/upload_313-/terminal/DDTPPE_201612.zip"
'~~> Destination for the file
strPath = "c:\Users\username\Desktop\WebTest\database.zip"
Ret = URLDownloadToFile(0, strURL, strPath, 0, 0)
End Sub
Thanks!
You can put your URL in a cell and run the script below.
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
Sub DownloadFilefromWeb()
Dim strSavePath As String
Dim URL As String, ext As String
Dim buf, ret As Long
URL = Worksheets("Sheet1").Range("A2").Value
buf = Split(URL, ".")
ext = buf(UBound(buf))
strSavePath = "C:\Users\your_path_here\" & "DownloadedFile." & ext
ret = URLDownloadToFile(0, URL, strSavePath, 0, 0)
If ret = 0 Then
MsgBox "Download has been succeed!"
Else
MsgBox "Error"
End If
End Sub
That's if you want to loop through a range with many URLs. If you want to download just one, try it this way.
Declare Function URLDownloadToFileA Lib "urlmon" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Sub ExampleDownload()
Dim IExpl As Object
Set IExpl = CreateObject("InternetExplorer.Application")
With IExpl
.Navigate "http://www.bom.mu/?id=80277" 'You need to change this for a variable and loop
Do Until .Readystate = 4: Loop ' Allow page to load
'Code below to find correct href link in page based on text
For Each lnk In IExpl.Application.Document.Links
If lnk.outertext = "Click Here to Open or Right Click to Download." Then Exit For
Debug.Print lnk.outertext
Next
End With
SuccessfulDownload = URLDownloadToFileA(0, lnk.href, "C:\myfilename.zip", 0, 0)
Set IExpl = Nothing
End Sub
Or, try R, which is blazing fast!! In order to get your data to download and uncompress, you need to set mode="wb"
download.file("...",temp, mode="wb")
unzip(temp, "gbr_Country_en_csv_v2.csv")
dd <- read.table("gbr_Country_en_csv_v2.csv", sep=",",skip=2, header=T)
Then, simply read the CSV from your Excel tool.