Results 1 to 6 of 6

Thread: [RESOLVED] Save an Opened Webpage as .txt

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Resolved [RESOLVED] Save an Opened Webpage as .txt

    Apologies if I'm in the wrong area; I'm new to all of this..

    I have the following, which will open a webpage using the parameters I require. I now need to save the resulting page as a txt file. The second half of the code is my attempt but I'm getting nowhere.

    Thanks in anticipation.

    Set IE = CreateObject("InternetExplorer.Application")
    IE.Navigate "http://www.nats-uk.ead-it.com/fwf-natsuk/public/user/account/login.faces?msg=user.access.required"
    IE.Visible = True
    Wscript.Sleep 5000
    IE.Document.All.Item("j_username").Value = "Tester"
    IE.Document.All.Item("j_password").Value = "Tester"
    IE.Document.All.Item("mainForm:login").Click
    Wscript.Sleep 3000
    IE.Document.All.Item("mainForm:notam_area").Click
    Wscript.Sleep 3000
    IE.Document.All.Item("mainForm:fir_0").Value = "EGTT" 'load FIRs
    IE.Document.All.Item("mainForm:generate").Click
    Wscript.Sleep 12000 'allow data to load



    '--------------------------------------------------------------------------------------------------------------------------------
    'Set docText = WebBrowser1.Document.Body.InnerText
    'Set objFile = objFSO.CreateTextFile(".\AreaBrief.txt", 2) 'create output doc
    'objFile.WriteLine docText 'write to output
    'objFile.Close 'close output
    'MsgBox ("Complete")
    Last edited by Parks; Nov 22nd, 2010 at 08:39 AM.

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Save an Opened Webpage as .txt

    Where did 'WebBrowser1' suddenly spring from ? You've been using IE for everything else.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Re: Save an Opened Webpage as .txt

    Doogle, you've seen right through me...

    I clearly have little idea as to what I'm doing. The first half of the script was cobbled together quickly and gave me a fair result. I then "researched" the saving bit, and that is what I found. Which language, protocols etc I'm actually using, I have no idea. Any help will be appreciated, and hopefully absorbed for the future.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Save an Opened Webpage as .txt

    I'd use a WebBrowser control right from the start.

    1. Create a new Project and add the 'Microsoft Internet Control' from Project -> Components
    2. Draw the control onto the Form and name it WebBrowser1
    3. Add a CommandButton and name it as cmdStart
    4. Copy and paste the code below into the Declarations Section of the Form
    5. Run and click the Button.
    It will create a file c:\Briefing.txt containing the output.
    Code:
    Option Explicit
    Private boComplete As Boolean
    Private intFile As Integer
    
    Private Sub cmdStart_Click()
    WebBrowser1.Navigate "http://www.nats-uk.ead-it.com/fwf-natsuk/public/user/account/login.faces?msg=user.access.required"
    Call WaitForBrowser
    WebBrowser1.Document.All.Item("j_username").Value = "Tester"
    WebBrowser1.Document.All.Item("j_password").Value = "Tester"
    WebBrowser1.Document.All.Item("mainForm:login").Click
    Call WaitForBrowser
    WebBrowser1.Document.getElementById("menuView:menuForm:notam_area").Click
    Call WaitForBrowser
    WebBrowser1.Document.getElementById("mainForm:fir_0").Value = "EGTT" 'load FIRs
    WebBrowser1.Document.getElementById("mainForm:generate").Click
    Call WaitForBrowser
    intFile = FreeFile
    Open "C:\Briefing.txt" For Output As intFile
    Print #intFile, WebBrowser1.Document.body.innerText
    Close intFile
    MsgBox "Briefing File Created"
    End Sub
    
    Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    boComplete = True
    End Sub
    
    Private Sub WaitForBrowser()
    boComplete = False
    Do Until WebBrowser1.ReadyState = READYSTATE_COMPLETE And boComplete = True
        DoEvents
    Loop
    End Sub
    Last edited by Doogle; Nov 22nd, 2010 at 10:02 AM.

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2010
    Posts
    3

    Re: Save an Opened Webpage as .txt

    Doogle, thanks for the swift & knowledgable response. Am trying it out, but may have to wait until tomorrow to access appropriate machine.

  6. #6
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Save an Opened Webpage as .txt

    My pleasure. Good luck

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