从文本文件中读取域并在浏览器中打开
Read Domains from Text File and Open in Browser
我在一个文本文件中列出了大约 100 多个网页,我必须对其进行分析。复制和粘贴可能很忙。
我认为 运行 脚本中的文本文件将一次打开一个域并在我关闭 IE 后打开下一个域。
如果可能,更新列表并删除访问过的列表,但如果工作量很大,我可以传递这个。
假设有:
yahoo.com
google.com
microsoft.com
PowerShell 它并没有真正起作用,因为我刚刚深入研究了 PowerSshell。
$domain = Get-Content ".\list.txt"
ForEach($element in $domain){
$url = "$domain"
$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate($url)
}
VBScript
这个
有效,但一次打开所有页面。如果有那么多 URL,这可能会崩溃。我该如何控制它?
Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile("list.txt")
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso
do while not listFile.AtEndOfStream fName = listFile.ReadLine()
Return = WshShell.Run("iexplore.exe " & fName, 1)
loop
注意:更新为包括删除已访问 URL 的行,并将 IE window 置于最前面。
这将使用 PowerShell 完成:
#VB assembly needed for function to bring IE to front
Add-Type -Assembly "Microsoft.VisualBasic"
$domain = Get-Content "c:\temp\list.txt"
ForEach($url in $domain){
#Start IE and make it visible
$ie = new-object -com "InternetExplorer.Application"
$ie.Visible = $true
#Bring the IE window to the front
$ieProc = Get-Process | ? { $_.MainWindowHandle -eq $ie.HWND }
[Microsoft.VisualBasic.Interaction]::AppActivate($ieProc.Id)
#Navigate to the URL
$ie.Navigate($url)
#Sleep while IE is running
while($ie.visible){
start-sleep -s 1
}
#Delete the URL from the file
(type c:\temp\list.txt) -notmatch "^$url$" | out-file c:\temp\list.txt
}
如果您想在脚本完成之前停止脚本,请转到 PowerShell window 并关闭它或按 Ctrl+C。
您的 VBScript 失败,因为您没有正确使用 .Run method。第三个参数 bWaitOnReturn 必须设置为 True。如
Const csFSpec = "31144615.txt"
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim goWS : Set goWS = CreateObject("WScript.Shell")
Dim tsIn : Set tsIn = goFS.OpenTextFile(csFSpec)
Do Until tsIn.AtEndOfStream
Dim sLine : sLine = tsIn.ReadLine
goWS.Run """C:\Program Files\Internet Explorer\IEXPLORE.EXE"" """ & sLine & """", 1, True
Loop
tsIn.Close
我在一个文本文件中列出了大约 100 多个网页,我必须对其进行分析。复制和粘贴可能很忙。
我认为 运行 脚本中的文本文件将一次打开一个域并在我关闭 IE 后打开下一个域。
如果可能,更新列表并删除访问过的列表,但如果工作量很大,我可以传递这个。
假设有:
yahoo.com
google.com
microsoft.com
PowerShell 它并没有真正起作用,因为我刚刚深入研究了 PowerSshell。
$domain = Get-Content ".\list.txt"
ForEach($element in $domain){
$url = "$domain"
$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate($url)
}
VBScript 这个 有效,但一次打开所有页面。如果有那么多 URL,这可能会崩溃。我该如何控制它?
Set fso = CreateObject("Scripting.FileSystemObject")
Set listFile = fso.OpenTextFile("list.txt")
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim fso
do while not listFile.AtEndOfStream fName = listFile.ReadLine()
Return = WshShell.Run("iexplore.exe " & fName, 1)
loop
注意:更新为包括删除已访问 URL 的行,并将 IE window 置于最前面。
这将使用 PowerShell 完成:
#VB assembly needed for function to bring IE to front
Add-Type -Assembly "Microsoft.VisualBasic"
$domain = Get-Content "c:\temp\list.txt"
ForEach($url in $domain){
#Start IE and make it visible
$ie = new-object -com "InternetExplorer.Application"
$ie.Visible = $true
#Bring the IE window to the front
$ieProc = Get-Process | ? { $_.MainWindowHandle -eq $ie.HWND }
[Microsoft.VisualBasic.Interaction]::AppActivate($ieProc.Id)
#Navigate to the URL
$ie.Navigate($url)
#Sleep while IE is running
while($ie.visible){
start-sleep -s 1
}
#Delete the URL from the file
(type c:\temp\list.txt) -notmatch "^$url$" | out-file c:\temp\list.txt
}
如果您想在脚本完成之前停止脚本,请转到 PowerShell window 并关闭它或按 Ctrl+C。
您的 VBScript 失败,因为您没有正确使用 .Run method。第三个参数 bWaitOnReturn 必须设置为 True。如
Const csFSpec = "31144615.txt"
Dim goFS : Set goFS = CreateObject("Scripting.FileSystemObject")
Dim goWS : Set goWS = CreateObject("WScript.Shell")
Dim tsIn : Set tsIn = goFS.OpenTextFile(csFSpec)
Do Until tsIn.AtEndOfStream
Dim sLine : sLine = tsIn.ReadLine
goWS.Run """C:\Program Files\Internet Explorer\IEXPLORE.EXE"" """ & sLine & """", 1, True
Loop
tsIn.Close