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

时间:2018-01-15 20:34:23

标签: internet-explorer autoit invisible

我的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)

1 个答案:

答案 0 :(得分:0)

  

...没有可见的Internet Explorer。

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

  

$iVisible [可选]指定浏览器窗口是否可见
0 =隐藏浏览器窗口
1 =(默认)浏览器窗口可见

示例:

#include <IE.au3>

Global Const $g_sUrl     = 'https://stackoverflow.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)