Navigate to a Website, SelectAll, Copy and Paste into a Notepad
Asked Answered
M

1

3

I'm trying to create a VB script to Navigate to a Website, SelectAll, Copy and then save the copied data from the clipboard to a text file, but I'm stuck! :(

Here is what I got so far:

With CreateObject("InternetExplorer.Application")
    .Navigate "https://www.microsoft.com"
    Do Until .ReadyState = 4: Wscript.Sleep 100: Loop
    .Visible = true
    With .Document
        .execCommand "SelectAll"
        .execCommand "Copy"
    End With ' Document
Mccollough answered 29/1, 2014 at 16:57 Comment(3)
This might be of some help.Bouillon
Problem is that webpage I want to collect the data uses JavaScript to render the data, so downloading source code of the page will not work since it does not contain that data. That's why I was going for a Select-All copy and pasteMccollough
VBScript is not the right tool for this kind of automation. Use something like AutoIt instead.Interrelate
B
3

You can try to get text data directly from DOM

With CreateObject("InternetExplorer.Application")
    .Visible = True
    .Navigate "https://www.microsoft.com"
    Do Until .ReadyState = 4
        Wscript.Sleep 100
    Loop
    For Each Tag In .Document.GetElementsByTagName("script")
        Tag.OuterHtml = ""
    Next
    For Each Tag In .Document.GetElementsByTagName("noscript")
        Tag.OuterHtml = ""
    Next
    Content = .Document.GetElementsByTagName("body")(0).InnerText
    Do While InStr(Content, vbCrLf & vbCrLf)
        Content = Replace(Content, vbCrLf & vbCrLf, vbCrLf)
    Loop
    ShowInNotepad Content
    .Quit
End With

Sub ShowInNotepad(Content)
    With CreateObject("Scripting.FileSystemObject")
        TempPath = CreateObject("WScript.Shell").ExpandEnvironmentStrings("%TEMP%") & "\" & .GetTempName
        With .CreateTextFile(TempPath, True, True)
            .WriteLine (Content)
            .Close
        End With
        CreateObject("WScript.Shell").Run "notepad.exe " & TempPath, 1, True
        .DeleteFile (TempPath)
    End With
End Sub
Braze answered 31/1, 2014 at 21:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.