导航到网站,全选,复制并粘贴到记事本中 [英] Navigate to a Website, SelectAll, Copy and Paste into a Notepad
本文介绍了导航到网站,全选,复制并粘贴到记事本中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个 VB 脚本来导航到网站、全选、复制,然后将复制的数据从剪贴板保存到一个文本文件,但我被卡住了!:(
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! :(
这是我目前得到的:
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
推荐答案
可以尝试直接从DOM获取文本数据
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屋!
查看全文