Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Find Link and select



  • Please log in to reply
22 replies to this topic
donaldb
  • Members
  • 7 posts
  • Last active: Jul 03 2013 04:03 AM
  • Joined: 30 Mar 2013

Hello All,

 

It may be a little over my head, but I thought I would ask if anyone could provide a litte more imput concerning a problem stressing me out. I am trying to navigate the moster web site using com functions with little sucess. I have been scouring all the turtorials and forums I can with little sucess. Here is what I have thanks to deleyed, jethro, and many others.

 

Pwb := ComObjCreate("InternetExplorer.Application")
Pwb.Visible := True
Pwb.Navigate(http://monster.com)
{pwb.Visible := true
while, pwb.busy
   sleep, 10
click 389, 293

Send, {Alt Down}
Send, {Space}
Send, {Alt Up}
Sleep, 1000
Send, {X}

 

 

}

Return

 

 

The problem is finding the spicific link and clicking into the link, then copying the page and saving it to word and placed in spicific file.  Thanks all I hope I havent caused anyone els deress as well!



donaldb
  • Members
  • 7 posts
  • Last active: Jul 03 2013 04:03 AM
  • Joined: 30 Mar 2013

I have tried to att the following to select links with little sucess.  does anyone  know what I am doing wrong?

 

COM_CoInitialize()
links := Com_Invoke(pwb, "document.all[_ale].all.tags[A]")

links := Com_Invoke(pwb, "document.links")
Loop, % Com_Invoke(links, "length") {
   link := Com_Invoke(links, "item", A_Index-1)
   Counter += 1
   if (Com_Invoke(link, "innerText") = "select")
 {
 IF (Counter < 4)
  continue
      Com_Invoke(link, "click")
   msgbox, clicked link.
   }
   Com_Release(link)
}
Com_Release(links)

COM_Release(pwb)
COM_CoUninitialize()



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
Hey sorry but it seems like your not really using the things right

Frist post the syntex is all over the place

And the second post is using the old com lib that is only needed if you are using ahk basic

Trie telling os more about the link you need click

Hope to help
Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

donaldb
  • Members
  • 7 posts
  • Last active: Jul 03 2013 04:03 AM
  • Joined: 30 Mar 2013

I appreciet the response Blackholyman.
 
I am trying to navigate monster.com (a job hunting website) for the perpose of:
 
-finding a spicific link
-Copying the content
-Then saving the content to a notpad document

-retreving the previous page to find the next appropriat link to repeat the process

 

Since it's a dynamic website it is really throwing me for a loop. plus, I'm such a noob any task is complicated for me:S

 

I tried using ^f looped to find the content and select it, but it is not consistant. I am at a loss.

 

Thanks



rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

What is the website URL?

Which specific link are you trying to click?

 

Run the following code and past the result into your reply:

info :=      "AHK Version:`t" A_AhkVersion 
   . "`nUnicode:`t`t" (A_IsUnicode ? "Yes " ((A_PtrSize=8) ? "(64-bit)" : "(32-bit)") : "No") 
   . "`nOperating System:`t" (!A_OSVersion ? A_OSType : A_OSVersion) 
   . "`nAdmin Rights:`t" (A_IsAdmin ? "Yes" : "No") 
MsgBox, 68, Support Information, %info%`n`nWould you like to copy this information to the Clipboard? 
IfMsgBox Yes 
{ 
   Clipboard := ""
   Clipboard := info 
   ClipWait 
   MsgBox, The information was sent to the Clipboard. 
} 
return

My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


donaldb
  • Members
  • 7 posts
  • Last active: Jul 03 2013 04:03 AM
  • Joined: 30 Mar 2013
 
I would like to select the links labeled "training"
 
AHK Version: 1.1.09.04
Unicode: Yes (32-bit)
Operating System: WIN_7
Admin Rights: No


donaldb
  • Members
  • 7 posts
  • Last active: Jul 03 2013 04:03 AM
  • Joined: 30 Mar 2013

Also, I mostly use Internet Explore; however, I do like using Google Chrome for the speed. 



rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

http://jobsearch.mon...ere=portland-or

I would like to select the links labeled "training"


Try this:

; AutoExecute
    #NoEnv
    #SingleInstance force
   
    OpenInBackgroundTab := 4096
   
    wb := ComObjCreate("InternetExplorer.Application")
    wb.Visible := true
    wb.Navigate("http://jobsearch.monster.com/search/training_5?where=portland-or")
    while wb.busy or wb.ReadyState != 4
        Sleep 0
    Links := wb.document.getElementsByTagName("a")
    Loop % Links.Length
        if InStr(Links[A_Index - 1].innerText, "Training")
            wb.Navigate(Links[A_Index - 1], OpenInBackgroundTab)
return

My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


robert_ilbrink
  • Members
  • 561 posts
  • Last active: Nov 07 2019 05:14 PM
  • Joined: 05 May 2012

Navigating in Chrome is very clumsy and relatively slow. The way I do it is in a loop 5 (don't want to try more than 5 subsequent searches). I use ^f (Find) to search for a specific string, escape to close the Find window, then check (with ^c) to see if the string was found anyway. If found, I use +F10 (Shift F10) to see if I can copy the url. When that is true, I know I have reached a link with the right search string and can press Enter to open it, else I search for the next string until I found a string with a URL. In other cases I use ImageSearch.



rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

Navigating in Chrome is very clumsy and relatively slow.


Automating FireFox via AHK is clumsy as well. I am normally a Firefox user, but for automation nothing beats IE via COM.


My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


donaldb
  • Members
  • 7 posts
  • Last active: Jul 03 2013 04:03 AM
  • Joined: 30 Mar 2013
✓  Best Answer

First of all supper insighful RobertllBrink

 

Navigating in Chrome is very clumsy and relatively slow. The way I do it is in a loop 5 (don't want to try more than 5 subsequent searches). I use ^f (Find) to search for a specific string, escape to close the Find window, then check (with ^c) to see if the string was found anyway. If found, I use +F10 (Shift F10) to see if I can copy the url. When that is true, I know I have reached a link with the right search string and can press Enter to open it, else I search for the next string until I found a string with a URL. In other cases I use ImageSearch.

 

Secondly, Briliance rbrtryn!

 

 

Try this:

; AutoExecute
    #NoEnv
    #SingleInstance force
   
    OpenInBackgroundTab := 4096
   
    wb := ComObjCreate("InternetExplorer.Application")
    wb.Visible := true
    wb.Navigate("http://jobsearch.monster.com/search/training_5?where=portland-or")
    while wb.busy or wb.ReadyState != 4
        Sleep 0
    Links := wb.document.getElementsByTagName("a")
    Loop % Links.Length
        if InStr(Links[A_Index - 1].innerText, "Training")
            wb.Navigate(Links[A_Index - 1], OpenInBackgroundTab)
return

 

 

I do have a few questions about what is going on in the script.  I have done what I can to understand each line; however, there are a few funcions I am still scratching my head wondering how they work.

 

 

 

Do you know of any refrece for the latest COM functions?

I have seen some librarys created by Sean that look amazing; however, I seem to be having troube finding any that are not out of date.

 

thanks for all the help!!!!

  •  



rbrtryn
  • Members
  • 1177 posts
  • Last active: Sep 11 2013 08:04 PM
  • Joined: 22 Jun 2011

Secondly, Briliance rbrtryn!


I can't really claim any brilliance here. Most of this I cobbled from the Word document here and the post here. Study the links there and I am sure you will begin to see what is going on.
 

I have seen some librarys created by Sean that look amazing; however, I seem to be having troube finding any that are not out of date.

 

All the COM functions are now built in to AHK and those libraries are no longer needed.


My Scripts are written for the latest released version of AutoHotkey.

Need a secure, accessible place to backup your stuff? Use Dropbox!


Vrajitoru
  • Members
  • 44 posts
  • Last active: Oct 06 2015 07:31 AM
  • Joined: 16 Mar 2010

Hi,

 

I'm trying to do something similar: Navigate to google.com, search something (Query variable) and get the result links into a txt file

 

Here is my code:

wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate("http://www.google.com")
while wb.Busy
    continue
wb.Document.All.q.Value := Query
wb.Document.All.btnK.Click()
while wb.busy or wb.ReadyState != 4
   Sleep 100
Sleep 5000
Links := wb.document.getElementsByTagName("a")
Msgbox, %Links%
FileAppend, %Links%, Test.txt

Everything is fine, but the content of the variable Links is empty.

 

Can anyone advice me what I'm doing wrong?

 

Thank you!



Jackie Sztuk _Blackholyman
  • Spam Officer
  • 3757 posts
  • Last active: Apr 03 2016 08:47 PM
  • Joined: 28 Feb 2012
Links := wb.document.getElementsByTagName("a")
Loop % links.length
   Links_urls .= Links[A_index-1].href "`n"


Msgbox %Links_urls%

Or this

Loop % (search_Links := wb.document.getElementById("search").getElementsByTagName("a")).length
   Links_urls .= search_Links[A_index-1].href "`n"

Msgbox %Links_urls%

Hope it helps


Helping%20you%20learn%20autohotkey.jpg?d

[AHK] Version. 1.1+ [CLOUD] DropBox ; Copy [WEBSITE] Blog ; About

Vrajitoru
  • Members
  • 44 posts
  • Last active: Oct 06 2015 07:31 AM
  • Joined: 16 Mar 2010

Thank you, Blackholyman

 

It helped, but not 100%

 

In google's results page, the actual links are somehow related to the google search.

 

Also here, there are the actual links where you are sent by google. They are stored within the tag <cite>Link</cite>, such as in the following example (I searched for autohotkey in this example):

<cite>
www.
    <b>autohotkey</b>
.com/
</cite>
...
<cite>
l.
<b>autohotkey</b>
.net/
</cite>
...
<cite>www.portablefreeware.com/?id=217</cite>

The tag <b> appears because the link contains the keyword, or part of the keyword (in case we have a phrase as keyword)

In this example, I would be interested to have the following 3 links:

- www.autohotkey.com

- l.autohotkey.net

- www.portablefreeware.com/?id=217

 

Sometimes, not sure based on what, the <cite> tag may have a class and a totally different text, such as this:

<cite class="bc">
download.cnet.com › ... ›
<a onmousedown="return rwt(this,'','','','12','AFQjCNGpHAOKqPDFBTa6RuJDhH9cw3834g','Wk1hThZzhgTA9ypNRV7Akw','0CHQQ6QUoADAL','','',event)" href="http://download.cnet.com/windows/automation-software/">Automation Software</a>
</cite>

In this case I would be interested to store the link from href: http://download.cnet...ation-software/

 

Any help is much appreciated - thank you!