Jump to content
Sign in to follow this  
vidaLL

Help with _IE UDF - href download

Recommended Posts

vidaLL

Hello guys....
I have a problem with this script. I can't download using href because each time that i generate a  document , the href will take the name of the document. So it varies by number of document.

Dim $sKey = 'HKCU\Software\Microsoft\Internet Explorer\New Windows'
RegWrite($sKEy, 'PopupMgr', 'REG_SZ', 'yes') ; Turn on
HotKeySet("{ESC}", "Terminate")

#include <WindowsConstants.au3>
#include <Excel.au3>
#include <IE.au3>



Local $sFilePath1 = @DesktopDir & "\Pasta2.xls"
;Global $sExcelFile = @DesktopDir & "\Pasta2.xls" ; <== Add the name of the Excel file here and your User
Local $oExcel = _ExcelBookOpen($sFilePath1)
Global $aExcelData = _ExcelReadSheetToArray($oExcel);$oExcel
$oIE = _IECreate()
_IENavigate($oIE, "https://www.fazenda.sp.gov.br/simp"); https://webhomolog.fazenda.sp.gov.br/simp

;=======================>FROM HERE
For $iRow = 1 To $aExcelData[0][0]
    $o_form = _IEFormGetObjByName($oIE, "form1")
    $o_txtCpf = _IEFormElementGetObjByName($o_form, "txtCpf")
    $o_txtNumDoc = _IEFormElementGetObjByName($o_form, "txtNumDoc")
    $O_btnConsultar = _IEFormElementGetObjByName($o_form, "btnConsultar")

    _IEFormElementSetValue($o_txtCpf, $aExcelData[$iRow][1])
    _IEFormElementSetValue($o_txtNumDoc, $aExcelData[$iRow][2])
    $o_btnConsultar.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "_ctl0")
    $o_btnContinuar = _IEFormElementGetObjByName($o_form, "btnContinuar")
    If IsObj($o_btnContinuar) Then
        $o_btnContinuar.click
        _IELoadWait($oIE)
    EndIf

    If Not IsObj($o_btnContinuar) Then
        $o_form = _IEFormGetObjByName($oIE, "Form1")
        $o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
        $o_btnGare.click
        _IELoadWait($oIE)
    EndIf

    ;$o_form = _IEFormGetObjByName($oIE, "Form1")
    ;$o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
    ;$o_btnGare.click
    ;_IELoadWait($oIE)

    ; Doc informations
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_txtObs = _IEFormElementGetObjByName($o_form, "txtObs")
    $o_txtDataPagto = _IEFormElementGetObjByName($o_form, "txtDataPagto")
    $o_txtReceita = _IEFormElementGetObjByName($o_form, "txtReceita")

    _IEFormElementSetValue($o_txtObs, $aExcelData[$iRow][3])
    _IEFormElementSetValue($o_txtDataPagto, $aExcelData[$iRow][4])
    _IEFormElementSetValue($o_txtReceita, $aExcelData[$iRow][5])
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnCalculoProd = _IEFormElementGetObjByName($o_form, "btnCalculoProd")
    $o_btnCalculoProd.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnGera = _IEFormElementGetObjByName($o_form, "btnGera")
    $o_btnGera.click
    _IELoadWait($oIE)

    WinWaitActive("https://www.fazenda.sp.gov.br/simp/guias", "")
    WinKill("https://www.fazenda.sp.gov.br/simp/guias", "")


;====DOWNLOAD MODE "SAVE AS"=====
   ;Sleep(6000)
   ;Send("{CTRLDOWN}")
   ;Send("{SHIFTDOWN}")
   ;Send("s")
   ;Send("{CTRLUP}")
   ;Send("{SHIFTUP}")
   ;Sleep(6000)
   ;WinWaitActive("Save as", "Save")
   ;Send("{ALTDOWN}")
   ;Send("s")
   ;Send("{ALTUP}")
   ;Sleep(1500)
   ;Send("!{F4}")
   ;Sleep(1500)

    $o_form = _IEFormGetObjByName($oIE, "Form1");_ctl0
    $o_btnSair = _IEFormElementGetObjByName($o_form, "btnSair")
    $o_btnSair.click
_IELoadWait($oIE)

Next

RegWrite($sKey, 'PopupMgr', 'REG_SZ', 'no') ; Turn off

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

I created a process in autoit that generate almost 200 registries. Each record generates a PDF and PDF's are the ones that I want to save on the desktop by e.g

SUMMARY: I need to know if there is any way to download it in background ?

Thanks you all.

Edited by vidaLL

Share this post


Link to post
Share on other sites
Realm

InetGet() ?

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites
vidaLL

Ok.  But , i have one case which href is <A id=gareLink href="guias/0_1302141343_0_005_DI_120-0_True_True.pdf">aqui</A> , but next time, tjhis part "0_1302141343_0_005_DI_120-0_True_True" will have another name .... Any idea ?

Share this post


Link to post
Share on other sites
DaleHohm

$oA = _IEGetObjByID($oIE, "gareLink")

$file = $oA.href

prepend $file with the rest of the site info and then use InetGet as suggested.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites
vidaLL

Dale, unfortunately i can't imagine what are you talking about :  :ermm:

I have this href : <A id=gareLink href="guias/0_1314891920_0_020_DI_120-0_True_True.pdf">aqui</A>

Im taking as example these scripts :

Local $hDownload = InetGet("http://www.autoitscript.com/autoit3/files/beta/update.dat", @Desktopdir & "\update.dat", 1, 1)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2) ; Check if the download is complete.
Local $nBytes = InetGetInfo($hDownload, 0)
InetClose($hDownload) ; Close the handle to release resources.
MsgBox(0, "", "Bytes read: " & $nBytes)

or just :

InetGet("http://www.autoitscript.com", @TempDir & "autoitscript.html", 1

Thanks :sweating:

Share this post


Link to post
Share on other sites
mLipok

I think @DaleHohm

mean somethink like this:

Local $hDownload = InetGet("www.somesite.com/guias/0_1314891920_0_020_DI_120-0_True_True.pdf", @TempDir & "\update.dat", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)

EDIT:

where "guias/0_1314891920_0_020_DI_120-0_True_True.pdf" is a part of this tag:

 

<A id=gareLink href="guias/0_1314891920_0_020_DI_120-0_True_True.pdf">aqui</A>

 

and "www.somesite.com/" is Your site adress

Edited by mlipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
vidaLL

Guys, I finally got it, but now my loop stopped working: (

HotKeySet("{ESC}", "Terminate")

#include <WindowsConstants.au3>
#include <Excel.au3>
#include <IE.au3>
#include <Array.au3>


Local $sFilePath1 = @DesktopDir & "\icms_importacao.xls"
;Global $sExcelFile = @DesktopDir & "\Pasta2.xls" ; <== Add the name of the Excel file here and your User
Local $oExcel = _ExcelBookOpen($sFilePath1)
Local $aExcelData = _ExcelReadSheetToArray($oExcel);$oExcel
$oIE = _IECreate()
_IENavigate($oIE, "https://www.fazenda.sp.gov.br/simp"); https://webhomolog.fazenda.sp.gov.br/simp


For $iRow = 1 To $aExcelData[0][0]
    $o_form = _IEFormGetObjByName($oIE, "form1")
    $o_txtCpf = _IEFormElementGetObjByName($o_form, "txtCpf")
    $o_txtNumDoc = _IEFormElementGetObjByName($o_form, "txtNumDoc")
    $O_btnConsultar = _IEFormElementGetObjByName($o_form, "btnConsultar")

    _IEFormElementSetValue($o_txtCpf, $aExcelData[$iRow][1])
    _IEFormElementSetValue($o_txtNumDoc, $aExcelData[$iRow][2])
    $o_btnConsultar.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "_ctl0")
    $o_btnContinuar = _IEFormElementGetObjByName($o_form, "btnContinuar")

    If IsObj($o_btnContinuar) Then
        $o_btnContinuar.click
        _IELoadWait($oIE)
    EndIf

    If Not IsObj($o_btnContinuar) Then
        $o_form = _IEFormGetObjByName($oIE, "Form1")
        $o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
        $o_btnGare.click
        _IELoadWait($oIE)
    EndIf

    ; Captar objetos dos documentos
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_txtObs = _IEFormElementGetObjByName($o_form, "txtObs")
    $o_txtDataPagto = _IEFormElementGetObjByName($o_form, "txtDataPagto")
    $o_txtReceita = _IEFormElementGetObjByName($o_form, "txtReceita")

    _IEFormElementSetValue($o_txtObs, $aExcelData[$iRow][3])
    _IEFormElementSetValue($o_txtDataPagto, $aExcelData[$iRow][4])
    _IEFormElementSetValue($o_txtReceita, $aExcelData[$iRow][5])
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnCalculoProd = _IEFormElementGetObjByName($o_form, "btnCalculoProd")
    $o_btnCalculoProd.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnGera = _IEFormElementGetObjByName($o_form, "btnGera")
    $o_btnGera.click
    _IELoadWait($oIE)


    ;Fecha pop up
    WinWaitActive("https://www.fazenda.sp.gov.br/simp/guias", "")
    WinKill("https://www.fazenda.sp.gov.br/simp/guias", "")

    ; Captar objetos dos documentos
    $o_form = _IEFormGetObjByName($oIE, "Form1");_ctl0
    $o_gareLink = _IEFormElementGetObjByName($o_form, "gareLink")
    $o_btnSair = _IEFormElementGetObjByName($o_form, "btnSair")


    ;Download PDF
    #include <Array.au3>
    $oLinks = _IELinkGetCollection ($oIE)
For $oLink In $oLinks
    If StringInStr ( $oLink.href, '.pdf' ) <> 0 And StringInStr ( $oLink.href, '.asc' ) = 0 Then
        ConsoleWrite ( "Link Inf : " & $oLink.innertext & ' : ' & $oLink.href & @Crlf )
        $_LastReleaseLink = $oLink.href
    EndIf
Next

    ;_IEQuit ( $oIE )
    $_Name = StringReplace ( _GetFullNameByUrl ( $_LastReleaseLink ), '%20', ' ' )
    InetGet ( $_LastReleaseLink, @ScriptDir & '\' & $_Name, 1 )
    RunWait ( @ScriptDir & '\' & $_Name & ' /S' )
Next
Func _GetFullNameByUrl ( $_FileUrl )

    $_FileName = StringSplit ( $_FileUrl, '/' )
    If Not @error Then
        Return $_FileName[$_FileName[0]]
    Else
        Return 0
    EndIf

$o_btnSair.click
_IELoadWait($oIE)
Endfunc
;RegWrite($sKey, 'PopupMgr', 'REG_SZ', 'no') ; Turn off
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Share this post


Link to post
Share on other sites
mLipok

try to use  _IEAction

for example

_IEAction ( $o_btnContinuar, "click")

instead

$o_btnContinuar.click

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library
 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-10-15

Share this post


Link to post
Share on other sites
vidaLL

I dont know exactly what i did ,but is working :

HotKeySet("{ESC}", "Terminate")

#include <WindowsConstants.au3>
#include <Excel.au3>
#include <IE.au3>
#include <Array.au3>


Local $sFilePath1 = @ScriptDir & "\icms_importacao.xls"
;Global $sExcelFile = @DesktopDir & "\Pasta2.xls" ; <== Add the name of the Excel file here and your User
Local $oExcel = _ExcelBookOpen($sFilePath1)
Local $aExcelData = _ExcelReadSheetToArray($oExcel);$oExcel
$oIE = _IECreate()
_IENavigate($oIE, "https://www.fazenda.sp.gov.br/simp"); https://webhomolog.fazenda.sp.gov.br/simp

For $iRow = 1 To $aExcelData[0][0]
    $o_form = _IEFormGetObjByName($oIE, "form1")
    $o_txtCpf = _IEFormElementGetObjByName($o_form, "txtCpf")
    $o_txtNumDoc = _IEFormElementGetObjByName($o_form, "txtNumDoc")
    $o_btnConsultar = _IEFormElementGetObjByName($o_form, "btnConsultar")

    _IEFormElementSetValue($o_txtCpf, $aExcelData[$iRow][1])
    _IEFormElementSetValue($o_txtNumDoc, $aExcelData[$iRow][2])
    $o_btnConsultar.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "_ctl0")
    $o_btnContinuar = _IEFormElementGetObjByName($o_form, "btnContinuar")

    If IsObj($o_btnContinuar) Then
        $o_btnContinuar.click
        _IELoadWait($oIE)
    EndIf

    If Not IsObj($o_btnContinuar) Then
        $o_form = _IEFormGetObjByName($oIE, "Form1")
        $o_btnGare = _IEFormElementGetObjByName($o_form, "btnGare")
        $o_btnGare.click
        _IELoadWait($oIE)
    EndIf

    ; Captar objetos dos documentos
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_txtObs = _IEFormElementGetObjByName($o_form, "txtObs")
    $o_txtDataPagto = _IEFormElementGetObjByName($o_form, "txtDataPagto")
    $o_txtReceita = _IEFormElementGetObjByName($o_form, "txtReceita")

    _IEFormElementSetValue($o_txtObs, $aExcelData[$iRow][3])
    _IEFormElementSetValue($o_txtDataPagto, $aExcelData[$iRow][4])
    _IEFormElementSetValue($o_txtReceita, $aExcelData[$iRow][5])
    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnCalculoProd = _IEFormElementGetObjByName($o_form, "btnCalculoProd")
    $o_btnCalculoProd.click
    _IELoadWait($oIE)

    $o_form = _IEFormGetObjByName($oIE, "Form1")
    $o_btnGera = _IEFormElementGetObjByName($o_form, "btnGera")
    $o_btnGera.click
    _IELoadWait($oIE)


    ;Fecha pop up
    WinWaitActive("https://www.fazenda.sp.gov.br/simp/guias", "")
    WinKill("https://www.fazenda.sp.gov.br/simp/guias", "")

    ; Captar objetos dos documentos
    $o_form = _IEFormGetObjByName($oIE, "Form1");_ctl0
    $o_gareLink = _IEFormElementGetObjByName($o_form, "gareLink")
    $o_btnSair = _IEFormElementGetObjByName($o_form, "btnSair")


    ;Download PDF
    $oLinks = _IELinkGetCollection ($oIE)
    For $oLink In $oLinks
    If StringInStr ( $oLink.href, '.pdf' ) <> 0 And StringInStr ( $oLink.href, '.asc' ) = 0 Then
        ConsoleWrite ( "Link Inf : " & $oLink.innertext & ' : ' & $oLink.href & @Crlf )
        $_LastReleaseLink = $oLink.href
    EndIf
Next
    $o_btnSair.click
    _IELoadWait($oIE)

    $_Name = StringReplace ( _GetFullNameByUrl ( $_LastReleaseLink ), '%20', ' ' )
    InetGet ( $_LastReleaseLink, @ScriptDir & '\' & $_Name, 1 )
    RunWait ( @ScriptDir & '\' & $_Name & ' /S' )
Next
Func _GetFullNameByUrl ( $_FileUrl )
    $_FileName = StringSplit ( $_FileUrl, '/' )
    If Not @error Then
        Return $_FileName[$_FileName[0]]
    Else
        Return 0
    EndIf
Endfunc

;RegWrite($sKey, 'PopupMgr', 'REG_SZ', 'no') ; Turn off
Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Thanks you all.

 

Edited by vidaLL

Share this post


Link to post
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
Sign in to follow this  

×