Results 1 to 4 of 4

Thread: [RESOLVED] Save as txt in c:\mydir, html page

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,635

    Resolved [RESOLVED] Save as txt in c:\mydir, html page

    Based this url:

    https://www.comuni-italiani.it/001/comuni.html

    how to save as txt entire html page?
    Tks

  2. #2
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,096

    Re: Save as txt in c:\mydir, html page

    How do you access the page currently from within your application?

  3. #3
    Hyperactive Member
    Join Date
    Jul 2022
    Posts
    317

    Re: Save as txt in c:\mydir, html page

    You can use this to save a page HMTL to a text file.
    I tried to use it with your link, but it timed out (edit: unable to use a browser either, maybe region locked?). Thus, I have the other one there for testing.

    Code:
        Dim HTTPRequest As MSXML2.XMLHTTP   ' *** need Reference to Microsoft XML, v3.0
        Dim url As String
            
        Dim fs As FileSystemObject                     ' *** need reference to Microsoft Scripting Runtime
        Dim pageAsTextStream As TextStream
        Dim pageAsTextFilename As String
                
        ' Open the HTTP request and send it
        'url = "https://www.comuni-italiani.it/001/comuni.html"
        url = "https://www.baseball-reference.com/leagues/majors/2024-standard-pitching.shtml"
        
        ' create the HTTP object and contact the website
        Set HTTPRequest = New MSXML2.XMLHTTP
    
        HTTPRequest.Open "GET", url, False
        HTTPRequest.send
            
        ' create the file name to save to
        pageAsTextFilename = "C:\Temp\" & Format(Now, "MM-dd-yyyy HHmmss") & "_comuni.txt"
        
        ' using the file system object, create a textfile with the html
        Set fs = New FileSystemObject
        Set pageAsTextStream = fs.CreateTextFile(pageAsTextFilename)
        
        pageAsTextStream.Write HTTPRequest.responseText
        pageAsTextStream.Close
        
        ' release the objects used
        Set pageAsTextStream = Nothing
        Set fs = Nothing
        
        Set HTTPRequest = Nothing

  4. #4
    Fanatic Member BenJones's Avatar
    Join Date
    Mar 2010
    Location
    Wales UK
    Posts
    694

    Re: Save as txt in c:\mydir, html page


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width