Jump to content

AutoIT OpenURL Firefox, Snipping and Send to TeleBOT - (Moved)


Recommended Posts

Dear Master,

I'm newbie in Autoit.
I want to make bot capture and send webpage url (Firefox) and send to my telegram Group with BOT,
But when i try to capture Webpage ( Elasticsearch ) its still loading but AUTOIT Start Capture, How to put waiting time before loading has finished?
 This is code:
 

#Include <IE.au3>
#Include <WinAPI.au3>
#Include <ScreenCapture.au3>
#Include <WindowsConstants.au3>
#Include "../src/AutoItObject.au3"
#include "../src/Telegram.au3"
#include "../src/FF.au3"
#include <Array.au3>

;Deklarasi Nama File
Local $ChatID = '<My ID Chat>' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token  = '<TOKENBOT>' ;Token here
Local $fileName1 = "media/APM ELK - CMS.png"
Local $fileName2 = "media/Discover ELK.png"


;Cek File sudah ada atau belum
If FileExists($fileName1) then
;Jika sudah ada, maka akan dihapus
   FileDelete($fileName1)
EndIf

;Cek File sudah ada atau belum
If FileExists($fileName2) then
;Jika sudah ada, maka akan dihapus
   FileDelete($fileName2)
EndIf

;Cek ID dan Token telegram bot
If(($ChatID = '') or ($Token = '')) Then
    ConsoleWrite("Warning! ChatID or Token not specified!")
    Exit -1
EndIf

_AutoItObject_StartUp()
OnAutoItExitRegister('OnExit')

WebCaptureTest("http://af-kubeelkprd01:5601/app/apm#/services", $fileName1)
ElementCaptureTest("http://af-kubeelkprd01:5601/app/kibana#/discover", $fileName2)

Func OnExit()
    _AutoItObject_Shutdown()
EndFunc

Func WebCaptureTest($Url, $ImageName)
    WinWait("","",30000)
    Local $hBmp = WebCapture($Url, 1366)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
 EndFunc

Func ElementCaptureTest($Url, $ImageName)
    Local $WebWidth = 1366
    Local $oIE = ObjCreate("Shell.Explorer.2")
    GUICreate("", $WebWidth, 800, -1, -1)
    GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 800)
    _IENavigate($oIE, $Url)
    Local $oElement = $oIE.document.documentElement
    If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body
    Local $hBmp = ElementCapture($oElement)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
EndFunc

Func WebCapture($Url, $WebWidth = 1366)
    Local Const $DVASPECT_CONTENT = 1
    Local $tIID_IViewObject2 = _AutoItObject_CLSIDFromString("{00000127-0000-0000-C000-000000000046}")
    Local $dtagIViewObject2 = $dtagIUnknown & "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);"
    Local $oIE = ObjCreate("Shell.Explorer.2")
    GUICreate("", $WebWidth, 800, -1, -1)
    GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 800)
    _IENavigate($oIE, $url)
    Local $oDocument = $oIE.document
    Local $oBody = $oIE.document.body
    Local $oHtml = $oIE.document.documentElement
    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'
    $oBody.style.overflow = 'hidden'
    Local $oIViewObject2 = _AutoItObject_WarpInterface($oDocument, $tIID_IViewObject2, $dtagIViewObject2)
    If @Error Then Return SetError(1, 0, 0)
    Local $BodyWidth = $oBody.scrollWidth
    Local $BodyHeight = $oBody.scrollHeight
    Local $RootWidth = $oHtml.scrollWidth
    Local $RootHeight = $oHtml.scrollHeight
    Local $Width = $BodyWidth
    Local $Height = $RootHeight
    If $BodyHeight > $Height Then $Height = $BodyHeight
    $oIE.width = $Width
    $oIE.height = $Height
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height)
    _WinAPI_SelectObject($hMemDc, $hBmp)
    Local $sRECT = DllStructCreate($tagRECT)
    DllStructSetData($sRECT, "Top", 0)
    DllStructSetData($sRECT, "Left", 0)
    DllStructSetData($sRECT, "Right", $Width)
    DllStructSetData($sRECT, "Bottom", $Height)
    $oIViewObject2.Draw($DVASPECT_CONTENT, -1, 0, 0, Number($hDC), Number($hMemDC), Number(DllStructGetPtr($sRECT)), 0, 0, 0)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC(0, $hDC)
   Return $hBmp
EndFunc

Func ElementCapture($oElement, $Border = 2)
    If Not IsObj($oElement) Then Return SetError(1, 0, 0)
    If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0)
    Local $tIID_IHTMLElementRender = _AutoItObject_CLSIDFromString("{3050F669-98B5-11CF-BB82-00AA00BDCE0B}")
    Local $dtagIHTMLElementRender = $dtagIUnknown & "DrawToDC hresult(hwnd);"
    Local $PageHeight = $oElement.scrollHeight - $Border
    Local $PageWidth = $oElement.scrollWidth - $Border
    Local $oIHTMLElementRender = _AutoItObject_WarpInterface($oElement, $tIID_IHTMLElementRender, $dtagIHTMLElementRender)
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight)
    Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight)
    _WinAPI_SelectObject($hMemDc, $hBmp)
    _WinAPI_SelectObject($hMemDcFull, $hBmpFull)
    Local $DrawWidth = $oElement.clientWidth - $Border
    Local $DrawHeight = $oElement.clientHeight - $Border
    Local $CurrentX = 0
    Local $CurrentY = 0
    While $CurrentX < $PageWidth
        While $CurrentY < $PageHeight
            $oElement.scrollLeft = $CurrentX
            $oElement.scrollTop = $CurrentY
            $oIHTMLElementRender.DrawToDC(Number($hMemDC))
            _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY)
            $CurrentY += $DrawHeight
        WEnd
        $CurrentY = 0
        $CurrentX += $DrawWidth
    WEnd
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteDC($hMemDcFull)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteObject($hBmp)
    Return $hBmpFull
EndFunc

Func _AutoItObject_WarpInterface($Obj, $IID, $Tag, $fNoUnknown = False)
    If Not IsDllStruct($IID) Then $IID = _AutoItObject_CLSIDFromString($IID)
    If Not IsObj($Obj) Then Return SetError(1, 0, 0)
    Local $pObj = _AutoItObject_IDispatchToPtr($Obj)
    If Not _AutoItObject_IUnknownAddRef($Obj) Then Return SetError(1, 0, 0)
    Local $ObjWarpped = _AutoItObject_WrapperCreate($pObj, $dtagIUnknown, $fNoUnknown)
    Local $aCall = $ObjWarpped.QueryInterface(Number(DllStructGetPtr($IID)), 0)
    If Not IsArray($aCall) And $aCall[0] <> 0 Then Return SetError(1, 0, 0)
    Local $pInterface = $aCall[2]
    Return _AutoItObject_WrapperCreate($pInterface, $Tag)
 EndFunc

 If FileExists($fileName1) then
         ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName1,"Test Kirim SS Dari URL") & @CRLF)
EndIf

 

Edited by Melba23
Link to comment
Share on other sites

  • Moderators

Moved to the appropriate forum.

Moderation Team

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

acam,

You are already in the correct forum.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Try this quick & dirty fix.  Add this line Sleep(20*1000) after _IENavigate($oIE, $url).

You need to do this at 2 places.

If that solves your immediate problem, we can think of a better solution later.

Edited by Nine
Link to comment
Share on other sites

After looking at the code more closely, I realized that it was kind of old code.  So I couldn't resist to "refresh" it with a more recent coding approach.  I may have solve at the same time your loading problem.  So there you go :

#include <IE.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>

Opt("MustDeclareVars", True)

Local $ChatID = '<My ID Chat>' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token = '<TOKENBOT>'  ;Token here
Local $fileName1 = "media/APM ELK - CMS.png"
Local $fileName2 = "media/Discover ELK.png"

If FileExists($fileName1) Then FileDelete($fileName1)
If FileExists($fileName2) Then FileDelete($fileName2)
If $ChatID = '' Or $Token = '' Then Exit MsgBox($MB_SYSTEMMODAL, "Warning", "ChatID or Token not specified!")

WebCaptureTest("https://www.google.ca", $fileName1)
ElementCaptureTest("https://www.google.ca", $fileName2)

Func WebCaptureTest($Url, $ImageName)
  Local $hBmp = WebCapture($Url)
  _ScreenCapture_SaveImage($ImageName, $hBmp, True)
EndFunc   ;==>WebCaptureTest

Func ElementCaptureTest($Url, $ImageName)
  Local $WebWidth = 1200
  Local $oIE = ObjCreate("Shell.Explorer.2")
  Local $hGUI = GUICreate("", $WebWidth, 800, -1, -1)
  GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800)
  _IENavigate($oIE, $Url)
  _IELoadWait($oIE)
  Local $oElement = $oIE.document.documentElement
  If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body
  Local $hBmp = ElementCapture($oElement)
  _ScreenCapture_SaveImage($ImageName, $hBmp, True)
  GUIDelete($hGUI)
EndFunc   ;==>ElementCaptureTest

Func WebCapture($Url, $WebWidth = 1200)
  Local $oIE = ObjCreate("Shell.Explorer.2")
  Local $hGUI = GUICreate("", $WebWidth, 800, -5000, -5000)
  GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800)
  _IENavigate($oIE, $Url)
  _IELoadWait($oIE)
  Local $oDocument = $oIE.document
  Local $oBody = $oIE.document.body
  Local $oHtml = $oIE.document.documentElement
  $oBody.scroll = "no"
  $oBody.style.borderStyle = "none"
  $oHtml.style.overflow = 'hidden'
  $oBody.style.overflow = 'hidden'
  Local $BodyWidth = $oBody.scrollWidth
  Local $BodyHeight = $oBody.scrollHeight
  Local $RootWidth = $oHtml.scrollWidth
  Local $RootHeight = $oHtml.scrollHeight
  Local $Width = $BodyWidth
  Local $Height = $RootHeight
  If $BodyHeight > $Height Then $Height = $BodyHeight
  $oIE.width = $Width
  $oIE.height = $Height
  GUISetState()
  Local $hBmp = Capture_Window($hGUI, 0, 0, $Width, $Height)
  GUIDelete($hGUI)
  Return $hBmp
EndFunc   ;==>WebCapture

Func Capture_Window($hWnd, $l, $t, $r, $b)
  Local $hDC_Capture = _WinAPI_GetDC($hWnd)
  Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
  Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $r, $b)
  Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap)
  _WinAPI_PrintWindow($hWnd, $hMemDC)
  _WinAPI_DeleteDC($hMemDC)
  _WinAPI_ReleaseDC($hWnd, $hDC_Capture)
  Return $hHBitmap
EndFunc   ;==>Capture_Window

Func ElementCapture($oElement, $Border = 2)
  If Not IsObj($oElement) Then Return SetError(1, 0, 0)
  If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0)
  Local $PageHeight = $oElement.scrollHeight - $Border
  Local $PageWidth = $oElement.scrollWidth - $Border
  Local $oIHTMLElementRender = ObjCreateInterface($oElement, "{3050F669-98B5-11CF-BB82-00AA00BDCE0B}", "DrawToDC hresult(hwnd);")
  Local $hDC = _WinAPI_GetDC(0)
  Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
  Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight)
  Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC)
  Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight)
  _WinAPI_SelectObject($hMemDC, $hBmp)
  _WinAPI_SelectObject($hMemDcFull, $hBmpFull)
  Local $DrawWidth = $oElement.clientWidth - $Border
  Local $DrawHeight = $oElement.clientHeight - $Border
  Local $CurrentX = 0
  Local $CurrentY = 0
  While $CurrentX < $PageWidth
    While $CurrentY < $PageHeight
      $oElement.scrollLeft = $CurrentX
      $oElement.scrollTop = $CurrentY
      $oIHTMLElementRender.DrawToDC(Number($hMemDC))
      _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY)
      $CurrentY += $DrawHeight
    WEnd
    $CurrentY = 0
    $CurrentX += $DrawWidth
  WEnd
  _WinAPI_DeleteDC($hMemDC)
  _WinAPI_DeleteDC($hMemDcFull)
  _WinAPI_ReleaseDC(0, $hDC)
  _WinAPI_DeleteObject($hBmp)
  Return $hBmpFull
EndFunc   ;==>ElementCapture

IDK, but I'm not even sure you need Func ElementCapture anymore.  Let me know how it goes...

Link to comment
Share on other sites

Hi @Nine,

Thanks for Help me,
You have solved my issue about Complete loading IE before capture with your code
 

sleep(40*1000) ;20 second is not enough for my apps

But my bot cannot send that picture to our group.

#include <IE.au3>
#include <WinAPI.au3>
#include <ScreenCapture.au3>
#include <WindowsConstants.au3>
#Include "../src/AutoItObject.au3"
#include "../src/Telegram.au3"
#include <Array.au3>

Opt("MustDeclareVars", True)

Local $ChatID = '<CHAT-ID>' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token  = '<BOT-TOKEN>' ;Token here
Local $fileName1 = "media/APM ELK - CMS.png"
Local $fileName2 = "media/Discover ELK.png"

If FileExists($fileName1) Then FileDelete($fileName1)
If FileExists($fileName2) Then FileDelete($fileName2)
If(($ChatID = '') or ($Token = '')) Then
    ConsoleWrite("Warning! ChatID or Token not specified!")
    Exit -1
EndIf
WebCaptureTest("<my_link>", $fileName1)
ElementCaptureTest("<my_link2>", $fileName2)

Func WebCaptureTest($Url, $ImageName)
  Local $hBmp = WebCapture($Url)
  _ScreenCapture_SaveImage($ImageName, $hBmp, True)
EndFunc   ;==>WebCaptureTest

Func ElementCaptureTest($Url, $ImageName)
  Local $WebWidth = 1200
  Local $oIE = ObjCreate("Shell.Explorer.2")
  Local $hGUI = GUICreate("", $WebWidth, 800, -1, -1)
  GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800)
  _IENavigate($oIE, $Url)
  _IELoadWait($oIE)
  Sleep(40*1000) ; added by Lord Nine
  Local $oElement = $oIE.document.documentElement
  If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body
  Local $hBmp = ElementCapture($oElement)
  _ScreenCapture_SaveImage($ImageName, $hBmp, True)
  GUIDelete($hGUI)
EndFunc   ;==>ElementCaptureTest

Func WebCapture($Url, $WebWidth = 1200)
  Local $oIE = ObjCreate("Shell.Explorer.2")
  Local $hGUI = GUICreate("", $WebWidth, 800, -5000, -5000)
  GUICtrlCreateObj($oIE, 0, 0, $WebWidth, 800)
  _IENavigate($oIE, $Url)
  _IELoadWait($oIE)
  Sleep(40*1000) ; added by Lord Nine
  Local $oDocument = $oIE.document
  Local $oBody = $oIE.document.body
  Local $oHtml = $oIE.document.documentElement
  $oBody.scroll = "no"
  $oBody.style.borderStyle = "none"
  $oHtml.style.overflow = 'hidden'
  $oBody.style.overflow = 'hidden'
  Local $BodyWidth = $oBody.scrollWidth
  Local $BodyHeight = $oBody.scrollHeight
  Local $RootWidth = $oHtml.scrollWidth
  Local $RootHeight = $oHtml.scrollHeight
  Local $Width = $BodyWidth
  Local $Height = $RootHeight
  If $BodyHeight > $Height Then $Height = $BodyHeight
  $oIE.width = $Width
  $oIE.height = $Height
  GUISetState()
  Local $hBmp = Capture_Window($hGUI, 0, 0, $Width, $Height)
  GUIDelete($hGUI)
  Return $hBmp
EndFunc   ;==>WebCapture

Func Capture_Window($hWnd, $l, $t, $r, $b)
  Local $hDC_Capture = _WinAPI_GetDC($hWnd)
  Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC_Capture)
  Local $hHBitmap = _WinAPI_CreateCompatibleBitmap($hDC_Capture, $r, $b)
  Local $hObject = _WinAPI_SelectObject($hMemDC, $hHBitmap)
  _WinAPI_PrintWindow($hWnd, $hMemDC)
  _WinAPI_DeleteDC($hMemDC)
  _WinAPI_ReleaseDC($hWnd, $hDC_Capture)
  Return $hHBitmap
EndFunc   ;==>Capture_Window

Func ElementCapture($oElement, $Border = 2)
  If Not IsObj($oElement) Then Return SetError(1, 0, 0)
  If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0)
  Local $PageHeight = $oElement.scrollHeight - $Border
  Local $PageWidth = $oElement.scrollWidth - $Border
  Local $oIHTMLElementRender = ObjCreateInterface($oElement, "{3050F669-98B5-11CF-BB82-00AA00BDCE0B}", "DrawToDC hresult(hwnd);")
  Local $hDC = _WinAPI_GetDC(0)
  Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
  Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight)
  Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC)
  Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight)
  _WinAPI_SelectObject($hMemDC, $hBmp)
  _WinAPI_SelectObject($hMemDcFull, $hBmpFull)
  Local $DrawWidth = $oElement.clientWidth - $Border
  Local $DrawHeight = $oElement.clientHeight - $Border
  Local $CurrentX = 0
  Local $CurrentY = 0
  While $CurrentX < $PageWidth
    While $CurrentY < $PageHeight
      $oElement.scrollLeft = $CurrentX
      $oElement.scrollTop = $CurrentY
      $oIHTMLElementRender.DrawToDC(Number($hMemDC))
      _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY)
      $CurrentY += $DrawHeight
    WEnd
    $CurrentY = 0
    $CurrentX += $DrawWidth
  WEnd
  _WinAPI_DeleteDC($hMemDC)
  _WinAPI_DeleteDC($hMemDcFull)
  _WinAPI_ReleaseDC(0, $hDC)
  _WinAPI_DeleteObject($hBmp)
  Return $hBmpFull
EndFunc   ;==>ElementCapture

;i want to send result capture to Bot telegram after finish capture
;but its still failed
If FileExists($fileName1) then
   ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName1,"Test Kirim SS Dari URL") & @CRLF)
EndIf

And this error result

 

Capture.PNG

Link to comment
Share on other sites

Well the photo has been taken correctly since you got the consolewrite stating that the file exists.  Now it seems that the _SendPhoto function is not working properly.   I am not familiar with Telegram Bot, but don't you need to _InitBot first ?

Edited by Nine
Link to comment
Share on other sites

This is Full Code:
 

#Include <IE.au3>
#Include <WinAPI.au3>
#Include <ScreenCapture.au3>
#Include <WindowsConstants.au3>
#Include "../src/AutoItObject.au3"
#include "../src/Telegram.au3"
#include "../src/FF.au3"
#include <Array.au3>

;Deklarasi Nama File
Local $ChatID = '<CHAT-ID>' ;Your ChatID here (take this from @MyTelegramID_bot)
Local $Token  = '<TOKEN-BOT>' ;Token here
Local $fileName1 = "<First NameFile>"
Local $fileName2 = "<Second Filename>"

;ConsoleWrite("Test file for Telegram UDF (https://github.com/xLinkOut/telegram-udf-autoit)." & @CRLF & _
;             "This file need a valid ChatID of a Telegram user who has already sent at least a message to the bot, and a valid token given by @BotFather." & @CRLF & _
;            "Insert this data in the source code." & @CRLF & @CRLF)

ConsoleWrite("! Initializing bot... " & _InitBot($Token) & @CRLF & @CRLF)

;Cek ID dan Token telegram bot
If(($ChatID = '') or ($Token = '')) Then
    ConsoleWrite("Warning! ChatID or Token not specified!")
    Exit -1
EndIf

;comments-start

;Cek File sudah ada atau belum
If FileExists($fileName1) then
;Jika sudah ada, maka akan dihapus
   FileDelete($fileName1)
EndIf

;Cek File sudah ada atau belum
If FileExists($fileName2) then
;Jika sudah ada, maka akan dihapus
   FileDelete($fileName2)
EndIf

_AutoItObject_StartUp()
OnAutoItExitRegister('OnExit')

WebCaptureTest("<First Link>", $fileName1)
ElementCaptureTest("<Second Link>", $fileName2)

Func OnExit()
    _AutoItObject_Shutdown()
EndFunc

Func WebCaptureTest($Url, $ImageName)
    Local $hBmp = WebCapture($Url, 1600)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
 EndFunc

Func ElementCaptureTest($Url, $ImageName)
    Local $WebWidth = 1600
    Local $oIE = ObjCreate("Shell.Explorer.2")
    GUICreate("", $WebWidth, 900, -1, -1)
    GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 900)
    _IENavigate($oIE, $Url)
    Sleep(40000) ; added by Lord Nine
    Local $oElement = $oIE.document.documentElement
    If $oElement.clientWidth = 0 Then $oElement = $oIE.document.body
    Local $hBmp = ElementCapture($oElement)
    _ScreenCapture_SaveImage($ImageName, $hBmp, True)
EndFunc

Func WebCapture($Url, $WebWidth = 1600)
    Local Const $DVASPECT_CONTENT = 1
    Local $tIID_IViewObject2 = _AutoItObject_CLSIDFromString("{00000127-0000-0000-C000-000000000046}")
    Local $dtagIViewObject2 = $dtagIUnknown & "Draw hresult(dword;long;ptr;ptr;dword;dword;ptr;ptr;int;dword);"
    Local $oIE = ObjCreate("Shell.Explorer.2")
    GUICreate("", $WebWidth, 900, -1, -1)
    GUICtrlCreateObj($oIE, 0, 0 , $WebWidth, 900)
    _IENavigate($oIE, $url)
    Sleep(40000) ; added by Lord Nine
    Local $oDocument = $oIE.document
    Local $oBody = $oIE.document.body
    Local $oHtml = $oIE.document.documentElement
    $oBody.scroll = "no"
    $oBody.style.borderStyle = "none"
    $oHtml.style.overflow = 'hidden'
    $oBody.style.overflow = 'hidden'
    Local $oIViewObject2 = _AutoItObject_WarpInterface($oDocument, $tIID_IViewObject2, $dtagIViewObject2)
    If @Error Then Return SetError(1, 0, 0)
    Local $BodyWidth = $oBody.scrollWidth
    Local $BodyHeight = $oBody.scrollHeight
    Local $RootWidth = $oHtml.scrollWidth
    Local $RootHeight = $oHtml.scrollHeight
    Local $Width = $BodyWidth
    Local $Height = $RootHeight
    If $BodyHeight > $Height Then $Height = $BodyHeight
    $oIE.width = $Width
    $oIE.height = $Height
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $Width, $Height)
    _WinAPI_SelectObject($hMemDc, $hBmp)
    Local $sRECT = DllStructCreate($tagRECT)
    DllStructSetData($sRECT, "Top", 0)
    DllStructSetData($sRECT, "Left", 0)
    DllStructSetData($sRECT, "Right", $Width)
    DllStructSetData($sRECT, "Bottom", $Height)
    $oIViewObject2.Draw($DVASPECT_CONTENT, -1, 0, 0, Number($hDC), Number($hMemDC), Number(DllStructGetPtr($sRECT)), 0, 0, 0)
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_ReleaseDC(0, $hDC)
   Return $hBmp
EndFunc

Func ElementCapture($oElement, $Border = 2)
    If Not IsObj($oElement) Then Return SetError(1, 0, 0)
    If $oElement.clientWidth = 0 Or $oElement.clientHeight = 0 Then Return SetError(1, 0, 0)
    Local $tIID_IHTMLElementRender = _AutoItObject_CLSIDFromString("{3050F669-98B5-11CF-BB82-00AA00BDCE0B}")
    Local $dtagIHTMLElementRender = $dtagIUnknown & "DrawToDC hresult(hwnd);"
    Local $PageHeight = $oElement.scrollHeight - $Border
    Local $PageWidth = $oElement.scrollWidth - $Border
    Local $oIHTMLElementRender = _AutoItObject_WarpInterface($oElement, $tIID_IHTMLElementRender, $dtagIHTMLElementRender)
    Local $hDC = _WinAPI_GetDC(0)
    Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmp = _WinAPI_CreateSolidBitmap(0, 0xffffff, $oElement.clientWidth, $oElement.clientHeight)
    Local $hMemDcFull = _WinAPI_CreateCompatibleDC($hDC)
    Local $hBmpFull = _WinAPI_CreateSolidBitmap(0, 0xffffff, $PageWidth, $PageHeight)
    _WinAPI_SelectObject($hMemDc, $hBmp)
    _WinAPI_SelectObject($hMemDcFull, $hBmpFull)
    Local $DrawWidth = $oElement.clientWidth - $Border
    Local $DrawHeight = $oElement.clientHeight - $Border
    Local $CurrentX = 0
    Local $CurrentY = 0
    While $CurrentX < $PageWidth
        While $CurrentY < $PageHeight
            $oElement.scrollLeft = $CurrentX
            $oElement.scrollTop = $CurrentY
            $oIHTMLElementRender.DrawToDC(Number($hMemDC))
            _WinAPI_BitBlt($hMemDcFull, $oElement.scrollLeft, $oElement.scrollTop, $DrawWidth, $DrawHeight, $hMemDC, $Border, $Border, $SRCCOPY)
            $CurrentY += $DrawHeight
        WEnd
        $CurrentY = 0
        $CurrentX += $DrawWidth
    WEnd
    _WinAPI_DeleteDC($hMemDC)
    _WinAPI_DeleteDC($hMemDcFull)
    _WinAPI_ReleaseDC(0, $hDC)
    _WinAPI_DeleteObject($hBmp)
    Return $hBmpFull
EndFunc

Func _AutoItObject_WarpInterface($Obj, $IID, $Tag, $fNoUnknown = False)
    If Not IsDllStruct($IID) Then $IID = _AutoItObject_CLSIDFromString($IID)
    If Not IsObj($Obj) Then Return SetError(1, 0, 0)
    Local $pObj = _AutoItObject_IDispatchToPtr($Obj)
    If Not _AutoItObject_IUnknownAddRef($Obj) Then Return SetError(1, 0, 0)
    Local $ObjWarpped = _AutoItObject_WrapperCreate($pObj, $dtagIUnknown, $fNoUnknown)
    Local $aCall = $ObjWarpped.QueryInterface(Number(DllStructGetPtr($IID)), 0)
    If Not IsArray($aCall) And $aCall[0] <> 0 Then Return SetError(1, 0, 0)
    Local $pInterface = $aCall[2]
    Return _AutoItObject_WrapperCreate($pInterface, $Tag)
 EndFunc

;comments-end

If FileExists($fileName1) then
   ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName1,"Name To Show") & @CRLF)
EndIf

If FileExists($fileName2) then
   ConsoleWrite("!" & @TAB & @TAB & "Sending photo: " & _SendPhoto($ChatID,$fileName2,"<Name To Show>") & @CRLF)
EndIf

But i have 1 issue more,
My App Monitoring don't support IE...

 

I dont know what i've to do. any idea?

Link to comment
Share on other sites

Are the links you have refer directly to images (.jpg or .png, or whatever) ?  I ask because it is photos that you send thru Telegram. 

Anyway, could you explain what is it you are trying to achieve ?  What is the end goal of your script ?

Edited by Nine
Link to comment
Share on other sites

Spoiler

 

Hi @Danp2,

I've 2 monitoring apps.

first Elasticsearch. It's support wiih IE, so i can get webpage screen capture like first image. But my second app monitoring don't support it like second image.

Hi @Nine

No, its url webpage. I just want to capture page from url, save to be image and send to telegram with bot. But 1 of my monitoring apps its not support IE...

IMG_20210403_073849_742.jpg

IMG_20210403_073908_653.jpg

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...