Sign in to follow this  
Followers 0
schuc

[SOLVED] Newbie Help: Auto clicking downlink link on Web form

18 posts in this topic

#1 ·  Posted (edited)

Hi all

I'm new to AutoIt, but loving it so far. I'm trying to create a script to automate updating the latest antivirus software from the net so my toolkit is always up to date. I am able to search CNET for Malwarebytes, but clicking on the first result via MouseClick() is unreliable due to the changing size of the ad above the search result links.

I would appreciate any help in finding out how to find and invoke the search result link programmatically.

antivirusupdate2.au3

Edited by schuc

Share this post


Link to post
Share on other sites



; Here is the current script (same as the attached file)

; ***********************************************************************

; Antivirus Update - Copy latest versions of Malwarebytes, Stinger, etc

; ***********************************************************************

;

#include <IE.au3>

; Declarations

Dim $sSaveBaseDir = "c:\utils\antivirus"

;

; MALWAREBYTES - Download latest from CNET

;

$oIE = _IECreate ("http://download.cnet.com/1770-20_4-0.html?query=malwarebytes+anti-malware&platformSelect=Windows&tag=srch&searchtype=downloads&filterName=platform%3DWindows&filter=platform%3DWindows")

; Select first item in cnet search results which should be latest MalwareBytes version

MouseClick("primary", 1080, 737) ;This is NOT reliable due to varying size of ad above link changing the link location

; How do I get the link handle itself so I can invoke a click on it directly?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi all

I'm new to AutoIt, but loving it so far. I'm trying to create a script to automate updating the latest antivirus software from the net so my toolkit is always up to date. I am able to search CNET for Malwarebytes, but clicking on the first result via MouseClick() is unreliable due to the changing size of the ad above the search result links.

I would appreciate any help in finding out how to find and invoke the search result link programmatically.

To start off with, can I suggest you put your text in autoit tags from now on please?

[code]Code Goes Here[ /autoit]
And that's how you do an autoit tag

OK.

The problem with your script is that it cant just click the first link, as that is most likely the link back to the homepage.

What you want to do is find out other places the file may be saved. For example, there is a marvelous script I found once that looks on a webpage, if the contents of that webpage (the version of the software) are greater than the softwares version, it downloads from 'the site/version/software package.exe'.

If you could find something like this (good luck) then you can save so much time, otherwise I don't think its possible, sorry.

shanet

Edited by shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

Below is the Summary results from the AU3Info Tool. I see that the Control sections doesn't show an ID or TEXT...

>>>> Window <<<<

Title: malwarebytes anti-malware downloads - Free software downloads and software reviews - CNET - Windows Internet Explorer provided

Class: IEFrame

Position: 717, 123

Size: 1132, 896

Style: 0x16CF0000

ExStyle: 0x00000100

Handle: 0x001B1BEA

>>>> Control <<<<

Class: Internet Explorer_Server

Instance: 1

ClassnameNN: Internet Explorer_Server1

Name:

Advanced (Class): [CLASS:Internet Explorer_Server; INSTANCE:1]

ID:

Text:

Position: 0, 117

Size: 1116, 718

ControlClick Coords: 411, 526

Style: 0x56000000

ExStyle: 0x00000000

Handle: 0x002F1924

>>>> Mouse <<<<

Position: 1136, 796

Cursor ID: 0

Color: 0x0066A0

>>>> StatusBar <<<<

1:

2:

3:

4:

5:

6:

7:

8:

9:

10:

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

Navigation Bar

http://download.cnet.com/1770-20_4-0.html?query=malwarebytes+anti-malware&platformSelect=Windows&tag=srch&searchtype=downloads&filterName=platform%3DWindows&filter=platform%3DWindows

Address Combo Control

Page Control

Search Combo Control

Search Control

Command Bar

Favorites Command Bar

LinksBand

Favorites Bar

Add to Favorites Bar

ITBarHost

Menu Bar

malwarebytes anti-malware downloads - Free software downloads and software reviews - CNET - Windows Internet Explorer provided

Zoom Level

>>>> Hidden Text <<<<

Bing

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

--REPEATED POST WILL NOT DELETE--

Edited by shanet

[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

To start off with, can I suggest you put your text in autoit tags from now on please?

[code]Code Goes Here[ /autoit]
And that's how you do an autoit tag

OK.

The problem with your script is that it cant just click the first link, as that is most likely the link back to the homepage.

What you want to do is find out other places the file may be saved. For example, there is a marvelous script I found once that looks on a webpage, if the contents of that webpage (the version of the software) are greater than the softwares version, it downloads from 'the site/version/software package.exe'.

If you could find something like this (good luck) then you can save so much time, otherwise I don't think its possible, sorry.

shanet

Thanks for your reply and my apologies regarding how I posted my code. This is actually my first posting to the board and didn't know how to do that. I will go try to edit my code posting above to add the "[autoit]" tag for readability.

Regarding accomplishing my goal of being able to programmatically "click" on a certain item in a web page based on characteristics(Text on link or first result from list, etc) not being possible, that's kind of surprising and disappointing. I know a lot of what I would want to automate and script would have to do with interacting with web pages and navigating those pages. This isn't possible without using a Click() function with blind coordinates? Really??

Share this post


Link to post
Share on other sites

I suggest you look in the autoit help files. They are really helpfull if you start off (like me too;) ). I think you are looking for something like:

_IELinkClickByText

or

_IELinkClickByIndex

The first one you can use if the name of the link stays the same. The second one if it always has the same index. I hope this is helpfull.

Greetings, Mr.PPP

Share this post


Link to post
Share on other sites

Thanks for your reply and my apologies regarding how I posted my code. This is actually my first posting to the board and didn't know how to do that. I will go try to edit my code posting above to add the "[autoit]" tag for readability.

Regarding accomplishing my goal of being able to programmatically "click" on a certain item in a web page based on characteristics(Text on link or first result from list, etc) not being possible, that's kind of surprising and disappointing. I know a lot of what I would want to automate and script would have to do with interacting with web pages and navigating those pages. This isn't possible without using a Click() function with blind coordinates? Really??

No problems at all, we all need to be educated, and we cant hold it against you that you are new.

...

Well if you could find some pattern in the URL, *maybe* you could come up with something?


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

I suggest you look in the autoit help files. They are really helpfull if you start off (like me too;) ). I think you are looking for something like:

_IELinkClickByText

or

_IELinkClickByIndex

The first one you can use if the name of the link stays the same. The second one if it always has the same index. I hope this is helpfull.

Greetings, Mr.PPP

You are absolutely correct. I was reading through lots of the docs, helpfiles and examples last night trying to get familiar before I started my first script and even though I did see the IE.au3 library, these particular functions escaped my notice when I started this exercise. As you noted, I'm still going to have to work something out if there are a number of objects with the same name, but it looks like I should take a closer look at that library again first before I bug anyone else with more questions.. :x

Thanks again.. much appreciated.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Hi all

I'm new to AutoIt, but loving it so far. I'm trying to create a script to automate updating the latest antivirus software from the net so my toolkit is always up to date.

I am able to search CNET for Malwarebytes,

but clicking on the first result via MouseClick() is unreliable due to the changing size of the ad above the search result links.

I would appreciate any help in finding out how to find and invoke the search result link programmatically.

Try like this ! Posted Image

#include <String.au3>

$_String = _GetSourceCode ( 'http://download.cnet.com/1770-20_4-0.html?query=malwarebytes+anti-malware&platformSelect=Windows&tag=srch&searchtype=downloads&filterName=platform%3DWindows&filter=platform%3DWindows' )
$_DownloadUrl1 = _StringBetween ( $_String, 'dlNow"> <a href="', '">Download Now' ) ; redirect link
If Not @error Then 
    $_String = _GetSourceCode ( $_DownloadUrl1[0] )
    $_DownloadUrl2 = _StringBetween ( $_String, '; URL=', '"/>' ) ; real download link
    If Not @error Then 
        $_Size = InetGetSize ( $_DownloadUrl2[0] )
        $_FileName = _StringBetween ( $_DownloadUrl2[0], '&fileName=', '' )
        If Not @error Then InetGet ( $_DownloadUrl2[0], @DesktopDir & '\' & $_FileName[0], 1, 0 )
    EndIf
EndIf

Func _GetSourceCode ( $_Url )
    $_InetRead = InetRead ( $_Url )
    If Not @Error Then
        $_BinaryToString = BinaryToString ( $_InetRead )
        If Not @Error Then Return $_BinaryToString
    EndIf   
EndFunc ;==> _GetSourceCode ( )
Edited by wakillon

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

Try like this ! Posted Image

I presume this worked for you, right? When I ran this code, $_DownloadUrl2 and $_Filename were both empty. Can you comment on this please?

Thanks

Share this post


Link to post
Share on other sites

I presume this worked for you, right? When I ran this code, $_DownloadUrl2 and $_Filename were both empty. Can you comment on this please?

Thanks

You may need to include IE.au3?


[font="Comic Sans MS"]My code does not have bugs! It just develops random features.[/font]My Projects[list][*]Live Streaming (Not my project, but my edited version)[right]AutoIt Wrappers![/right][/list]Pure randomness[list][*]Small Minds.......................................................................................................[size="1"]Simple progress bar that changes direction at either sides.[/size][*]ChristmasIt AutoIt Christmas Theme..........................................................[size="1"]I WAS BOOOORED![/size][*]DriveToy..............................................................................................................[size="1"]Simple joke script. Trick your friends into thinking their computer drive is haywire![/size][/list]In Development[list][*]Your Background Task Organiser[*]AInstall Second Generation[/list]BEFORE POSTING ON THE FORUMS, TRY THIS:
%programfiles%/AutoIt3/autoit3.chm

Share this post


Link to post
Share on other sites

FYI that while working on this, I ran into a problem trying to get past the IE security preventing file downloads. Even stranger is what happened when I added the domain to the IE trusted sites list.

I created a new topic for the issue which is

Share this post


Link to post
Share on other sites

You may need to include IE.au3?

What's the relevance with my post ?

No need, script works well, Schuc must reset his IE settings ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

What's the relevance with my post ?

No need, script works well, Schuc must reset his IE settings ! Posted Image

Thanks for your follow-up reply wakillon.

As I noted in my earlier reply, $_DownloadUrl2 and $_Filename were empty when I ran your code and it wasn't working for me.

Would you tell me what you mean about I need to reset my IE settings?

Thanks

Edited by schuc

Share this post


Link to post
Share on other sites

Thanks for your follow-up reply wakillon.

As I noted in my earlier reply, $_DownloadUrl2 and $_Filename were empty when I ran your code and it wasn't working for me.

Would you tell me what you mean about I need to reset my IE settings?

Thanks

Try script with all this consolewrite i think you will quickly understand ! Posted Image

#include <String.au3>

$_String = _GetSourceCode ( 'http://download.cnet.com/1770-20_4-0.html?query=malwarebytes+anti-malware&platformSelect=Windows&tag=srch&searchtype=downloads&filterName=platform%3DWindows&filter=platform%3DWindows' )
$_DownloadUrl1 = _StringBetween ( $_String, 'dlNow"> <a href="', '">Download Now' ) ; redirect link
If Not @error Then 
    $_String = _GetSourceCode ( $_DownloadUrl1[0] )
    $_DownloadUrl2 = _StringBetween ( $_String, '; URL=', '"/>' ) ; real download link
    If Not @error Then 
        ConsoleWrite ( "-->-- $_DownloadUrl2[0] : " & $_DownloadUrl2[0] & @Crlf )
        $_Size = InetGetSize ( $_DownloadUrl2[0] )
        ConsoleWrite ( "-->-- $_Size : " & $_Size & @Crlf )
        $_FileName = _StringBetween ( $_DownloadUrl2[0], '&fileName=', '' )
        ConsoleWrite ( "!->-- $_FileName : " & $_FileName[0] & @Crlf )
        If Not @error Then InetGet ( $_DownloadUrl2[0], @DesktopDir & '\' & $_FileName[0], 1, 0 )
    EndIf
EndIf

Func _GetSourceCode ( $_Url )
    $_InetRead = InetRead ( $_Url )
    If Not @Error Then
        $_BinaryToString = BinaryToString ( $_InetRead )
        If Not @Error Then Return $_BinaryToString
    EndIf   
EndFunc ;==> _GetSourceCode ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Try script with all this consolewrite i think you will quickly understand ! Posted Image

This is Fantastic!

Thanks for the great help. I'm already having fun breaking down the (perfectly working) code you shared. In the end, this is a MUCH better solution for what I'm trying to do. I am still curious about why I was having the issues with the file download block banner even after putting the domain in the trusted list, but I'm not going to worry about that now. I'm going to learn how this is working better and maybe put a progress bar in as a small exercise for myself.

Now that I see the messages in the console and see that the filename was parsed out of the link and downloaded without even starting IE, I think this is a way better solution for me.

Thanks wakillon! <--:x

Edited by schuc

Share this post


Link to post
Share on other sites

Thanks

Downloading by script is always better than wait for IE download windows,

and you can customize the download.

Use ConsoleWrite without moderation, it permits to understand better or debug script easily ! Posted Image


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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  
Followers 0