Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Automate save as HTML for multiple URLs

Posted on 2015-02-21
6
Medium Priority
?
65 Views
Last Modified: 2016-02-10
I have a list of 180 URLs all of which point to static web pages. I want to automate the task of saving each as an individual HTML file. Is this possible?
0
Comment
Question by:K_Deutsch
  • 3
  • 3
6 Comments
 
LVL 12

Expert Comment

by:FarWest
ID: 40623932
sure, you can make an excel sheet that contains URLs List, and destination HTML files name (or use formula to auto generate those names) and then run vba script like the one in this url
stackoverflow.com/questions/13193210/can-i-save-a-webpage-source-html-dynamically-using-vba-in-my-local-machine
 
but be aware that there is a glitch related to embedding images in the page, they will point to their original url
0
 

Author Comment

by:K_Deutsch
ID: 40624354
Sounds good and I did a test on a single web page, but I must confess I am clueless as to how to incorporate (into VBA) the multiple URL and file name data from my two Excel columns.

URL List
http://www.abc.com
http://www.def.com

Destination file name list
abc.html
def.html
0
 
LVL 12

Accepted Solution

by:
FarWest earned 2000 total points
ID: 40624381
attached working sample
EE-Book1SaveWebUrl.xlsm
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:K_Deutsch
ID: 40624511
When I run your sample with my URLs I get a ERROR_WINHTTP_NAME_NOT_RESOLVED error (server name could not be resolved). However, going back to the link you posted to the stackoverflow earlier, if I use just one of my specific URLs (similar to what you see in bold below) it works.

We may have gotten outside of the original scope of this question.


Sub GetHTTP()
Dim objHttp As Object
Dim CachedFilePath As String
    Set objHttp = CreateObject("MSXML2.ServerXMLHTTP")
   Call objHttp.Open("GET", "http://www.abc.com/content/502", False)
    Call objHttp.Send("")
    CachedFilePath = Environ("temp") & "\" & "ReplaceThisWithFilename" & ".html"
    Call CreateFile(CachedFilePath, objHttp.ResponseText)
End Sub

Function CreateFile(FileName As String, Contents As String) As String
' creates file from string contents
Dim tempFile As String
Dim nextFileNum As Long
  nextFileNum = FreeFile
  tempFile = FileName
  Open tempFile For Output As #nextFileNum
  Print #nextFileNum, Contents
  Close #nextFileNum
  CreateFile = tempFile
End Function
0
 
LVL 12

Expert Comment

by:FarWest
ID: 40624592
Just in case use ltrim and rtrim  functions on the URL cell value
It maybe caused by spaces
I'm away from my computer. But it seems URL specific problem.
0
 

Author Comment

by:K_Deutsch
ID: 40624628
My list of URLs included the http://. Once I cut that out it works now. Thank you!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As computers become more powerful, jobs will be replaced with artificial intelligence, leaving no place in the future for humans in the workforce. In the oncoming technological revolution, the staggering change to human mind labor will prove the ski…
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Where to go on the main page to find the job listings. How to apply to a job that you are interested in from the list that is featured on our Careers page.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Suggested Courses

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question