如何在不使 Internet Explorer 可见的情况下实现自动化?

How to automate without making Internet Explorer visible?

我的 AutoIt 脚本执行 Google 搜索查询。对于每一个,它都会得出美元与另一种货币的兑换率。它显示 Internet Explorer,我不希望它显示。

代码如下:

#include <Constants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIEdit.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <array.au3>
#include <String.au3>
#include <IE.au3>

$oIE = _IECreate()
_IENavigate($oIE, "https://www.google.com/search?q=convert+us+dollars+to+euros")
$aText = _IEBodyReadText($oIE)
If StringInStr($aText, "equals") Then
    $num_pos = StringInStr($aText, "equals")
    $one_num = StringMid($aText, ($num_pos + 10), 4)
EndIf

_IENavigate($oIE, "https://www.google.com/search?q=convert+us+dollars+to+japanese+yen")
$aText = _IEBodyReadText($oIE)
If StringInStr($aText, "equals") Then
    $num_pos = StringInStr($aText, "equals")
    $two_num = StringMid($aText, ($num_pos + 10), 6)
EndIf

_IENavigate($oIE, "https://www.google.com/search?q=convert+us+dollars+to+british+pounds")
$aText = _IEBodyReadText($oIE)
If StringInStr($aText, "equals") Then
    $num_pos = StringInStr($aText, "equals")
    $three_num = StringMid($aText, ($num_pos + 10), 4)
EndIf

_IENavigate($oIE, "https://www.google.com/search?q=convert+us+dollars+to+aruban+florins")
$aText = _IEBodyReadText($oIE)
If StringInStr($aText, "equals") Then
    $num_pos = StringInStr($aText, "equals")
    $four_num = StringMid($aText, ($num_pos + 10), 4)
EndIf

$res_string = $one_num & "+" & $two_num & "+" & $three_num & "+" & $four_num
MsgBox($MB_OK, "Here are the results", $res_string)

… without Internet Explorer being visible.

根据Documentation - User Defined Function Reference - _IECreate()

$iVisible [optional] specifies whether the browser window will be visible
0 = Browser Window is hidden
1 = (Default) Browser Window is visible

示例:

#include <IE.au3>

Global Const $g_sUrl     = 'https://whosebug.com/'
Global Const $g_iAttach  = 0
Global Const $g_iVisible = 0
Global Const $g_iWait    = 1
Global Const $g_iFocus   = 0

Global       $g_oIE      = _IECreate($g_sUrl, $g_iAttach, $g_iVisible, $g_iWait, $g_iFocus)
Global       $g_sPage    = _IEBodyReadText($g_oIE) & @CRLF

ConsoleWrite($g_sPage)
_IEQuit($g_oIE)