Sign in to follow this  
Followers 0
vrap

Finding text on a page, and then some..

11 posts in this topic

Basic run down is that i want to check a page for some text, if it is there, to click the last link found on the page, this is what i have so far, but it doesnt seem to work:

#include <IE.au3>

$waiting = 0

$oIE = _IECreate("http://somelink.net")

while $waiting = 0

$sText = _IEBodyReadText ($oIE)

$iNumLinks = @extended

$last_link = _IELinkGetCollection($oIE, $iNumLinks - 6); get the 6th last link ..

$result = StringInStr($sText, "beautiful") ; check for the text beautiful

if not $result = 0 then

_IEAction($last_link, "click")

$waiting = 1

EndIf

Sleep(1200)

_IENavigate ($oIE, "http://somelink.net") ; refresh?

wend

any ideas, i cant seem to find any info on checking a page for text :S

Share this post


Link to post
Share on other sites



Is the beautiful string is part of the inner or outer link string? Does it supposed to appear only once in the entire body source?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

yes its only supposed to appear once. and it only will if its there.

EDIT: in fact, if i could isolate the text at a certain point in the page it would be even better. :)

Edited by vrap

Share this post


Link to post
Share on other sites

Try this few notes:

-First don't navigate again to the same site, instead, use _IEAction($oIE, 'refresh') and _IELoadWait($oIE).

-Make sure that "$iNumLinks - 6" can't return negative results or you're going to get 0 as the return value or a collection if computing it results in -1.

-"if not $result = 0 then" is quite confusing. Use If $result instead.

The rest seems OK related to logical and syntactical code but I do think that storing the @extended macro after a call to _IEBodyReadText doesn't supposed to return any link related value. Use @extended after calling _IELinkGetCollection($oIE)

Share this post


Link to post
Share on other sites

Perfect, thanks, i only just started coding in autoit 20 mins or so ago before i posted, just needed this personal script: heres the result if anyone is interested:

#include <IE.au3>

$waiting = 0

$oIE = _IECreate("http://blah.net")

while $waiting = 0

$sText = _IEBodyReadText ($oIE)

$oLinks = _IELinkGetCollection ($oIE, 0)

$iNumLinks = @extended

$last_link = _IELinkGetCollection($oIE, $iNumLinks - 1); -2 means 2nd last link and so on

$result = StringInStr($sText, "enter")

if $result then

;MsgBox(0, "Last link is: ", $last_link.href)

_IEAction($last_link, "click")

$waiting = 1

ExitLoop

EndIf

_IEAction($oIE, 'refresh')

_IELoadWait($oIE)

wend

will search for beautiful and click last link. tyvm.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

just a quick Q, is it possible to click the link as soon as the text loads, because it seems the site takes a while to fully load due to ads :S

edit: AND, say its clicked on the link because it found the text, how can i check the text on the new page that has been loaded.

Edited by vrap

Share this post


Link to post
Share on other sites

Ah nvm got it, is there anyway to go back to the start of a script?

Share this post


Link to post
Share on other sites

Yup, put everything you want before the While..WEnd loop inside a function and call it whenever you wish inside the loop.

Actually going to the back of the script as it's deduced is not possible except for as mentioned above or put it all in a loop which is not wise or relaunch your program before terminating yours (must be compiled if I'm not wrong) which is the most unwise method ever.

Try the first approach with the function.

Share this post


Link to post
Share on other sites

Yeh thats what i ended up doing, just thought because it was a more user friendly language it might have one of those handy return to start of script functions, autoit is a pretty handy language ive realised, thanks for the help, my code seems to be growing quite rapidly.

Share this post


Link to post
Share on other sites

u can use all customized loops Do, while, for ...

Share this post


Link to post
Share on other sites

Yeh i know, im fluent in a couple of other languages, just wanted to see if it had a candy function to make things easier :)

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