Jump to content
Sign in to follow this  
Mr.Sniper

How do i search pages for links?

Recommended Posts

Mr.Sniper

I want to make a script that can search through pages of the internet until it finds a certain link and then clicks on that link... so lets say that you are on google and you search spiders and you want to search all the links that google came up with until you find one that has the word "ugly" in it... so how would you make a script that says find {text} ???


Share this post


Link to post
Share on other sites
SmOke_N

I'm sure DaleHolm will be along shortly to emphasize using COM and taking a look at his IE.au3. But ... be prepared to duck until then.

GL...


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
LxP

Welcome to the forums!

You can use InputBox() to get information from the user. You can use the INetGet() to download a webpage. AutoIt has a good range of string manipulation functions that would help you work with the files you download (you may be particularly interested in StringInStr(), StringRegExpReplace() and StringSplit() maybe, but it would depend on how you plan to accomplish things).

Good luck!

Edit: And of course Dale's IE automation library would make life a lot easier for something like this. Ron beat me to it.

Edited by LxP

Share this post


Link to post
Share on other sites
DaleHohm

@ronsrules, @LxP -- I'm obliged not to disappoint you :whistle:

IE.au3 has a function called _IEClickLinkByText() that would be very close to what you want, however it is written to do an exact match of the link text and not a sub-string match [i've considered adding a string match method switch to the function calls, but I am concerned with making them too complocated].

You could easily make a local (renamed) copy of _IEClickLinkByText in your script modified slightly to fit your needs. Like this:

Note: if you find this confusing, please ask questions. See my sig for IE.au3

#include <IE.au3>

$oIE = _IECreate()
_IENavigate($oIE, "http://www.google.com")

$oForm = _IEFormGetObjByName($oIE, "f")
$oQuery = _IEFormElementGetObjByName($oForm, "q")

_IEFormElementSetValue($oQuery, "your ugly search string")
_IEFormSubmit($oForm)
_IELoadWait($oIE)

MyClickLinkByText($oIE, "Next"); There is no good "ugly" link on the first page, goto Next
MyClickLinkByText($oIE, "ugly"); click on the ugly link

Exit

Func MyClickLinkByText($o_object, $s_linkText, $i_index = 0, $f_wait = 1)
   ; _IE_clickLinkText( $o_object, $s_linkText [, $i_index][, $f_wait])
   ; $o_object - Object Valiable pointing to an InternetExplorer.Application object
   ; $s_linkText - linkText, the text displayed on the web page for the desired link to click
   ; [$i_index] - if the link text occurs more than once, specify which instance you want to click
   ;        note: instance numbering starts at 0
    $doc = $o_object.document
    $links = $doc.links
    $found = 0
    For $link In $links
        $linkText = $link.outerText & ""; Append empty string to prevent problem with no outerText (image) links
        If StringInStr($linkText, $s_linkText) Then;;; Look for SubString instead of exact match
            if ($found = $i_index) Then
                $result = $link.click
                If ($f_wait = 1) Then _IELoadWait($o_object)
                SetError(0)
                Return 1
            EndIf
            $found = $found + 1
        EndIf
    Next
    SetError(1)
    Return 0
EndFunc

I want to make a script that can search through pages of the internet until it finds a certain link and then clicks on that link... so lets say that you are on google and you search spiders and you want to search all the links that google came up with until you find one that has the word "ugly" in it... so how would you make a script that says find {text} ???

<{POST_SNAPBACK}>


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

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  

×