Dent

How to download uniquely generated PDF?

20 posts in this topic

Hi everyone,

My script uses IE11 on Win7 to log in to a site and enters data into a couple of forms. Upon clicking a link this data is used by the site to generate a PDF report.

With my current set-up if I do this manually the PDF opens in a new IE tab and I can download or print it. If I right-click the link that creates the PDF and choose Save Target As the PDF is generated and the Open/Save As dialogue at the bottom of the screen opens. All good.

However I would like the script to automatically download the PDF and close IE and then exit. Closing IE (_IEQuit) and exiting the script are easy enough, but I'm struggling getting the script to download the PDF.

The link to generate the PDF contains a unique number each time the page with the link is reached, so it's not static. The link position however, using _IELinkGetCollection I can tell the link to generate the PDF is always the 10th one from the end of the page, so using $iNumLinks - 10 I am able to click the link.

What I believe I need to use is InetGet however the problem I've been facing is that the link isn't static and I haven't worked out a way to access the link by index - is this possible?

Here is the website HTML for the section containing the link although I don't think it's of much use but it at least shows the format of the link (I can't post a link as it's a password protected area)...

<div class="rmButton right"><a title="Generates a PDF version of the market report in a new window." href="/rmplus/generatePdf?mr_id=60991" target="_blank">print/save as pdf</a></div>

The full link https://www.rightmove.co.uk/rmplus/generatePdf?mr_id=60991 just for completeness - visiting it will give a HTTP 500 unless logged in.

And here is the code that clicks this link opening the generated PDF in a new tab...

$oLinks = _IELinkGetCollection($oIE)
$iNumLinks = @extended
$PrintPDF = _IELinkClickByIndex($oIE, ($iNumLinks - 10))

So, how to use InetGet to visit that link? Or is there a way to Save As the newly opened tab? I've tried _IEAction($oIE, "saveas") but it seems not to work in a tab containing only a PDF.

Share this post


Link to post
Share on other sites



7 minutes ago, Dent said:

The full link https://www.rightmove.co.uk/rmplus/generatePdf?mr_id=60991 just for completeness - visiting it will give a HTTP 500 unless logged in.

 

This is what I get when I click this link:

Quote

Sorry

Sorry there is a problem

Reference No #2301-161111-100642-10401

 


NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

Two ways (first method is easier):

- download all the page content with _IEBodyReadHTML and retrieve your mr_id through regular expressions (StringRegExp)

- use .getattribute method to retrieve href attribute in the div with "Generates a PDF version of the market report in a new window." a title attribute.

Then you can build full link and use InetGet to download the file.

Share this post


Link to post
Share on other sites

HREF is not pointing directly to PDF file , so I'm not sure if InetGet will work.

 


NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

Thank-you both for your input.

j0kky, I was really hoping your first method would work - I don't know why I didn't think of this, but I have a habit of coding whilst tired.

So I used StringInStr and StringMid etc to obtain the actual link, here's the code...

$Page = _IEBodyReadHTML($oIE)
$PrintPDFStart = StringInStr($Page, "?mr_id=")
$PrintPDFEnd = StringMid($Page, $PrintPDFStart, 12)
$PrintPDF = ("https://www.rightmove.co.uk/rmplus/generatePdf" & $PrintPDFEnd)
$hDownload = InetGet($PrintPDF, @ScriptDir & "\Report.pdf")
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2)
InetClose($hDownload)

I checked the result of $PrintPDF to be sure the URL is 100% correct, which it is, but unfortunately the script just hangs. mLipok you were right :(

I haven't tried your second method as I also don't see this working as I think the problem is with InetGet()

I think the answer may lie in trying to save the PDF from the newly created IE tab.

Share this post


Link to post
Share on other sites

Q1

In this new tab can you manualy Save this pdf file ? I want to know the file name.

Q2

When this new tab is open , how You close them ?

 

Ps.

Long time ago I had the same problem 

 


NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

Hi mLipok and thanks for replying again.

Q1. In the new tab which just has the title 'rightmove.co.uk' I can manually save the pdf and the filename is 'generatePDF.pdf' but I haven't been able to save it using AutoIt yet.

Q2. I have only been able to close the tab manually, I have tried _IEAttach to the new tab and then _IEQuit but it doesn't work. I think I would need to interact with the interface by simulating a mouse-click.

Share this post


Link to post
Share on other sites

I think I have solution to Q1.

But I'm not able to find it quickly .

 

1 person likes this

NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

#10 ·  Posted

I think part of the issue is that you didn't indicate that InetGet should download the file in the background. The revised code should look like

$hDownload = InetGet($PrintPDF, @ScriptDir & "\Report.pdf", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2)

The other issue that you are likely running into is that the InetGet will fail due to security reasons. In the past, I have resolved this by _IECreateEmbedded within a hidden GUI so that the web browser is running in the same context as the script.

Share this post


Link to post
Share on other sites

#11 ·  Posted

8 hours ago, Danp2 said:

I think part of the issue is that you didn't indicate that InetGet should download the file in the background. The revised code should look like

$hDownload = InetGet($PrintPDF, @ScriptDir & "\Report.pdf", $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
Do
    Sleep(250)
Until InetGetInfo($hDownload, 2)

The other issue that you are likely running into is that the InetGet will fail due to security reasons. In the past, I have resolved this by _IECreateEmbedded within a hidden GUI so that the web browser is running in the same context as the script.

Thanks Danp2, it could be a context thing, InetGet doesn't return an error it just hangs. I don't think I'll be able to sniff the connection either as it's SSL.

I tried your variation above and the same thing happens. InetRead at least does return that 0 bytes have been read so I guess it is getting blocked.

Maybe using IUAutomation is the way and actually controlling the new tab that is created when the link is clicked - but I've never used that UDF.

Share this post


Link to post
Share on other sites

#12 ·  Posted

10 hours ago, mLipok said:

I think I have solution to Q1.

But I'm not able to find it quickly .

 

Something like this:

_Example()
Func _Example()
    Local $sIECacheDir = _IE_GetCacheDir()
    Local $aKatalogi = _FileListToArrayRec($sIECacheDir, 'generatePDF*.pdf', 1, 1, 0, 2)
EndFunc


Func _IE_GetCacheDir()
    Local $sIECacheDir = RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\', 'Cache')
    $sIECacheDir = StringReplace($sIECacheDir, '%USERPROFILE%', @UserProfileDir)
    Return SetError(0, 0, $sIECacheDir)
EndFunc   ;==>_IE_GetCacheDir

 


NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

#13 ·  Posted

11 hours ago, Dent said:

Q2. I have only been able to close the tab manually, I have tried _IEAttach to the new tab and then _IEQuit but it doesn't work. I think I would need to interact with the interface by simulating a mouse-click.

Can you post here HTML snippet with this second IE tab ?
_IEAttach works ?
Try to change IE content before Quit, just like that:

Local _IEAttach(......
    $sHTML = _
            "<HTML>" & @CRLF & _
            "<HEAD>" & @CRLF & _
            "<TITLE>Empty Page</TITLE>" & @CRLF & _
            "</HEAD>" & @CRLF & _
            "</HTML>" & _
            ""
    _IEDocWriteHTML($oIE, $sHTML)
    _IEQuit($oIE)

 


NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

The new IE tab that is created just displays the pdf so I cannot control it with any _IE functions and there is no HTML source to view.

I think I'll have to control the window in some other way :(

Share this post


Link to post
Share on other sites

#15 ·  Posted

 

8 minutes ago, Dent said:

displays the pdf so I cannot control it with any _IE functions and there is no HTML source to view.

Are you sure ?

Try this:

#include <IE.au3>

_Example()
Func _Example()
    Local $sURL = 'http://lipok.pl/test_pdf/nicniewidac.html'

    Local $oIE = _IECreate($sURL)
    Local $sHTML = _IEDocReadHTML($oIE)
    MsgBox(0, '', $sHTML)

    $sHTML = _
            "<HTML>" & @CRLF & _
            "<HEAD>" & @CRLF & _
            "<TITLE>Empty Page</TITLE>" & @CRLF & _
            "</HEAD>" & @CRLF & _
            "</HTML>" & _
            ""

    _IEDocWriteHTML($oIE, $sHTML)

EndFunc   ;==>_Example

 

When this MsgBox PopUp try to use F12 (I know do not not works), but then try Developers Tools from IE Menu >>  Tool's

 

 

43 minutes ago, Dent said:

The new IE tab that is created just displays the pdf so I cannot control it with any _IE functions

Here is another interesting example:

 


NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

#17 ·  Posted

Did you try my snippet from #13

??

btw.
If I'm thinking correctly you can use :

using one of this:
_WinINet_FindFirstUrlCacheEntryEx
_WinINet_FindNextUrlCacheEntryEx
_WinINet_FtpCommand
_WinINet_InternetFindNextFile

 


NEW:     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

Last update: 2016-11-12
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 Components * TeamViewer API -UDF * JavaManagement UDF * VIES over SOAPPOP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF * WinSCP UDF *

My contribution to others projects: * _sql.au3 UDF  *

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 * Best coding practices * 

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 *

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."

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

Would anyone be able to VNC into my machine and try to resolve this?

I would happily give the login details out but there is an email verification process that means I would need to be involved, if you VNC to my machine it is already configured correctly.

mLipok, yes I tried your snippet from #13 but it didn't work.

Share this post


Link to post
Share on other sites

#19 ·  Posted

Another option, for whatever it's worth, would be to use WinHttp. Forum thread here.

1 person likes this

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Quick example (from here):

#include "WinHttp.au3"
Global $hOpen = _WinHttpOpen()
Global $hConnect = _WinHttpConnect($hOpen, 'daveismyname.com')
Global $hRequest = _WinHttpOpenRequest($hConnect, 'POST', '/demos/formpdf/', Default, 'https://daveismyname.com/demos/formpdf/')
_WinHttpSendRequest($hRequest, 'Content-Type: application/x-www-form-urlencoded', 'name=Dent&email=dent%40wayfarer.com&submit=Submit')
_WinHttpReceiveResponse($hRequest)
If _WinHttpQueryDataAvailable($hRequest) Then
    Global $sHeaders = _WinHttpQueryHeaders($hRequest)
    Global $sFile = @ScriptDir & '\' & StringRegExpReplace($sHeaders, '(?si).*filename="(\S+)".*', '$1')
    Global $dChunk, $dData
    While 1
        $dChunk = _WinHttpReadData($hRequest, 2)
        If @error Then ExitLoop
        $dData = _WinHttpSimpleBinaryConcat($dData, $dChunk)
    WEnd
    Global $hFile = FileOpen($sFile, 26)
    FileWrite($hFile, $dData)
    FileClose($hFile)
    If Not FileExists($sFile) Then MsgBox(48, "Error occurred", "No file created." & @CRLF)
    ShellExecute($sFile)
Else
    MsgBox(48, "Error occurred", "No data available." & @CRLF)
EndIf
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

 

Edited by GMK
Correct code; add link
2 people like this

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

  • Similar Content

    • PunkoHead
      IE function to click on nav button
      By PunkoHead
      Hi all,
      I am having an issue with a website that I want to automate.
      I have this menu and I want to click on the Custom button.

       
       
      The buttons with "inspect element" are: 
       

       
      The code that I tried is
      $sSearch = "Custom" $oFrame = _IEFrameGetObjByName($oIE, "options") $oDivs = _IETagNameGetCollection($oFrame, "ul") For $oDiv In $oDivs If String(_IEPropertyGet($oDiv, "InnerText")) = $sSearch Then _IEAction($oDiv, "click") ExitLoop EndIf Next I also tried with:
      $sMyString = "Custom" Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      However, these are not working. Any ideas?
       
       
    • AnAdventurer
      Newbie with a question... or two (IE focused)
      By AnAdventurer
      Hello hello!
      As the title suggests, I am fairly new to AutoIt. In fact, I am new to scripting/coding in general! I've done a few Codecademy courses on CSS and HTML and perhaps Java though this was all a few years back. I've recently come across AutoIt and decided to give it a try since I do quite a few repetitive tasks on a daily basis. In the last couple of weeks I've managed to master (or at least get comfortable with) mouse clicks(left/right), window focus, sending key strokes, controls, and pixel search.
      Now let's get to the topic.
      At this point in time I've tried out a few simple IE scripts but I am having difficulty understanding some things and tying everything together into one tool.
      Specifically, I am struggling with this little bit of code I got from DaleHohm in his IE examples thread. Post #3 (The last example.)
      #include <IE.au3> $sImgDir = "c:\foo\"; Please make certain this folder already exists (silent failure if not) $sWebPage = "http://www.autoitscript.com/forum/index.php?"; webpage with images $oIE = _IECreate() _IENavigate($oIE, $sWebPage) $oIMGs = _IETagNameGetCollection($oIE.document, "img") ; Loop through all IMG tags and save file to local directory using INetGet For $oIMG in $oIMGs $sImgUrl = $oIMG.src $sImgFileName = $oIMG.nameProp INetGet($sImgUrl, $sImgDir & $sImgFileName) Next I have a couple questions about the code above.
      1) ".src" ".nameProp" What are these called? I figured out that I can change the .src to something like .href and it gets anything on the webpage with a .href tag but where can I learn more about these? I still haven't been able to figure out what ".nameProp" is for or what it does. Is there any documentation/list of all the different ".PurpleTextAfterAVariable" (Edit: Not sure why it's red in the above example, just checked SciTE and it's purple there) that I can use?
      2) I understand that the code above gets every "For $oIMG in $oIMGs" on the page but how can I make it only get the first 5? I've tried doing a "count" and a "for" but I am unsure what to replace the "For...in" statement with to keep the script functional. Is there a way to limit the _IETagNameGetCollection function to only get a specific amount of tags?
       
      Finally, the reason I can't just use the code as is.
      The site I am trying to get images from works in this way:
      A href= "Link-To-Picture.jpg" Img src= "Link-To-Picture-thumbnail.jpg" The script above downloads every single thumbnail from the image gallery which is great, it does what it's supposed to but I need the full resolution image.
      After changing the script to get anything with an "A href" tag it does what I need it to do, it gets every single image in full resolution... along with every single one of the 80-100 extra files/links to other sites that are listed under an "A href" tag.
       
      Now I've come up with two solutions but unfortunately, as I mentioned above. I don't know how to put my solution into the code above to make it work.
      Solution 1) Only get the first 5 instances of "A href" on the page.
      As mentioned above. I don't know how to do this.
      Solution 2) Read the entire page, find "-Thumbnail.jpg" replace with ".jpg" and use the script as is.
      I understand how to do a replace. All I am missing is how to do a replace within a field in the code of an IE page. I assume that I have to use the HTMLRead functions but how do I use/alter the data read?
      I really hope all of this make sense and that someone here will be able to help me figure out a solution to my issue or at least answer one of my questions! I do have plenty more questions and I am sure that I'll have even more by the time I figure this out.
      Thank you very much for your time!
    • Muhammad_Awais_Sharif
      InetGet correct way of checking error during downloading a file
      By Muhammad_Awais_Sharif
      I am using this code to Download a file 
      I don't know correct way of checking error during downloading
      Global $DownloadStatus = InetGet($url, $fileName, Default, $INET_DOWNLOADBACKGROUND) While 1 $ArrayOFDownloadStatuts = InetGetInfo($DownloadStatus) If Not $ArrayOFDownloadStatuts[4] = 0 Then MsgBox(0,"Error","Error During Downloading") ExitLoop EndIf If $ArrayOFDownloadStatuts[2] Then MsgBox(0,"","Compelted") ExitLoop EndIf WEnd I am using that code but don't know why it gives error during downloading the file 

      is it wrong way of checking error or is there network error on my pc ?  
      thank you  
    • Muhammad_Awais_Sharif
      UrlDownloadEx run in background
      By Muhammad_Awais_Sharif
      Hi
      I want to run  UrlDownloadEx  run in background so GUI don't hang.
      It should give response During Downloading any file with this udf.
      Please Help me 
      Thank you 
       
    • Juvigy
      IE automation
      By Juvigy
      Hi Guys,
      I have a very complex IE page with lots of Java and Iframes. I need to be able to look for a change in one <input> field. So what i have done is to identify the field and hook an event listener with ObjEvent($title, "_Evt_")  and then i use :
      Func _Evt_OnChange() Local $o_object = @COM_EventObj ConsoleWrite( "Change" & $o_object.value &@CRLF) _FileWriteLine($MainLog, "Change:" & _NOW()) TitleCheck($o_object.value) EndFunc Which work fine user doesn't interact with some of the other buttons or radios on the page. As soon as the user does some interaction or refreshes the page or navigates - the event listener is 'deleted' somehow and no longer works. Any idea how to counteract that? The easiest this is to detect if there is ANY change on the page - then i can identify the INPUT and check for its value. Any idea how to do that ?