Solved

Automate save as HTML for multiple URLs

Posted on 2015-02-21
6
51 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 500 total points
ID: 40624381
attached working sample
EE-Book1SaveWebUrl.xlsm
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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: 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.

Question has a verified solution.

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

EE introduced a new rating method known as Level, which displays in your avatar as LVL. The new Level is a numeric ranking that is based on your Points. This article discusses the rationale behind the new method and provides the mathematical formula…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Saved searches can save you time by quickly referencing commonly searched terms on any topic. Whether you are looking for questions you can answer or hoping to learn about a specific issue, a saved search can help you get the most out of your time o…
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…

820 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