我有30个不同的网页,我试图制作一个脚本来复制所有文本并将其粘贴到30个不同的txt文件并保存 - 全部在后台。
到目前为止,我成功为一个网页创建了一个脚本,但是我遇到了创建一个.vbs文件的问题,该文件将对所有30个页面执行。我以为我可以将我的代码30x复制/粘贴到页面底部,只需修改网站的源/目的地即可。但它没有。
With CreateObject("internetexplorer.application")
.Navigate "http://example.com"
Do Until .ReadyState = 4
Wscript.Sleep 100
Loop
.Document.execcommand "SelectAll"
.Document.execCommand "copy"
End With
'paste
Const ForAppending = 8
Dim sFSpec
sFSpec = ".\file1.txt"
Dim oIE
Dim sText
Set oIE = CreateObject( "InternetExplorer.Application" )
oIE.Navigate( "about:blank" )
sText = oIE.document.parentwindow.clipboardData.GetData( "text" )
CreateObject( "Scripting.FileSystemObject" )_
.OpenTextFile( sFSpec, ForAppending, True )_
.WriteLine sText
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Below, I just copy and paste it, but the code here doesn't work
With CreateObject("internetexplorer.application")
.Navigate "http://example1.com"
Do Until .ReadyState = 4
Wscript.Sleep 100
Loop
.Document.execcommand "SelectAll"
.Document.execCommand "copy"
End With
'paste
Const ForAppending = 8
Dim sFSpec1
sFSpec1 = ".\dev01-envVar.txt"
Dim oIE1
Dim sText1
Set oIE1 = CreateObject( "InternetExplorer.Application" )
oIE1.Navigate( "about:blank" )
sText1 = oIE1.document.parentwindow.clipboardData.GetData( "text" )
CreateObject( "Scripting.FileSystemObject" )_
.OpenTextFile( sFSpec, ForAppending, True )_
.WriteLine sText
还是比使用vbscripting更简单的方法?
此外,IE总是给我这个弹出消息 - “你想让这个网页访问你的剪贴板吗?”如何删除弹出窗口? Remove this popup!
答案 0 :(得分:0)
您使用PowerShell标记标记了您的问题,所以这是:
"http://example.com", "http://gmail.com" | % {
$ie = New-Object -ComObject internetexplorer.application
$ie.Navigate($_)
while ($ie.ReadyState -ne 4){
Start-Sleep -Milliseconds 100
}
$ie.Document.execCommand("SelectAll") | Out-Null
Out-File -InputObject $ie.Document.selection.createRange().text `
-FilePath "D:\Temp\$($ie.Document.title).txt"
$ie.Quit()
}
答案 1 :(得分:0)
Sinse你提到了PowerShell标签:
已编辑在powershell v2.0中工作
Add-Type -AssemblyName system.windows.forms
[System.Windows.Forms.Clipboard]::Clear() # just to be sure
$sitesList = @(
'http://example.com',
<#
More sites here
#>
'http://www.example.com'
)
foreach ($site in $sitesList) {
$ie = New-Object -ComObject "internetexplorer.application"
$ie.Navigate($site)
while ($ie.ReadyState -ne 4) {
Start-Sleep -Milliseconds 100
}
$ie.Document.execCommand( "SelectAll" )
$ie.Document.execCommand( "copy" )
$filename = ($site -replace "^http://") + '.txt'
[System.Windows.Forms.Clipboard]::GetText() | Out-File "D:\$filename" -Force
[System.Windows.Forms.Clipboard]::Clear()
$ie.Quit()
}
答案 2 :(得分:0)
Set objShell = CreateObject("Shell.Application")
Set AllWindows = objShell.Windows
For Each window in AllWindows
msgbox window.locationname
If window.locationname="Scripts" then window.quit
Next
这将列出Explorer和Internet Explorer中的所有打开的shell窗口。