Solved

Automate save as HTML for multiple URLs

Posted on 2015-02-21
6
48 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Originally published Entrepreneur.com Booming numbers of freelancing professionals are changing the face of work. In the United States alone last year, the number of workers freelancing grew from 700,000 to 54 million, according to a Freelancers’…
I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
The Bounty Board allows you to request an article or video on any technical topic, or fulfill a bounty request to earn points. Watch this video to learn how to use the Bounty Board to get the content you want, earn points, and browse submitted bount…
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…

786 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