Navigate to a Website, SelectAll, Copy and Paste into a Notepad

后端 未结 1 820
日久生厌
日久生厌 2020-12-10 09:01

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

相关标签:
1条回答
  • 2020-12-10 09:34

    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
    
    0 讨论(0)
提交回复
热议问题