导航到网站,选择所有,复制并粘贴到记事本中 [英] Navigate to a Website, SelectAll, Copy and Paste into a Notepad

查看:369
本文介绍了导航到网站,选择所有,复制并粘贴到记事本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个VB脚本来导航到一个网站,SelectAll,复制,然后将复制的数据从剪贴板保存到文本文件,但我被卡住了! :(



这是我到目前为止所得到的:

  With CreateObject(InternetExplorer.Application)
.Navigatehttps://www.microsoft.com
Do Until .ReadyState = 4:Wscript.Sleep 100:Loop
.Visible = true
使用.Document
.execCommandSelectAll
.execCommandCopy
以'Document

解决方案

您可以尝试直接从DOM获取文本数据

 使用CreateObject(InternetExplorer.Application)
.Visible = True
.Navigatehttps://www.microsoft.com
Do Until .ReadyState = 4
Wscript.Sleep 100
Loop
For Each Tag In .Document.GetElementsByTagName(script)
Tag.OuterHtml =
Next
For每个Tag In .Document.GetElementsByTagName(noscript)
Tag.OuterHtml =
Next
Content = .Document.GetElementsByTagNa me(body)(0).InnerText
做InStr(内容,vbCrLf& vbCrLf)
内容=替换(内容,vbCrLf& vbCrLf,vbCrLf)
循环
ShowInNotepad内容
。美元
结束时

Sub ShowInNotepad(内容)
使用CreateObject(Scripting.FileSystemObject)
TempPath = CreateObject(WScript.Shell)。ExpandEnvironmentStrings(%TEMP%)& \& .GetTempName
使用.CreateTextFile(TempPath,True,True)
.WriteLine(内容)
。关闭

结束使用CreateObject(WScript.Shell)。运行notepad.exe& TempPath,1,True
.DeleteFile(TempPath)

结束Sub


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

解决方案

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

这篇关于导航到网站,选择所有,复制并粘贴到记事本中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆