Sign in to follow this  
Followers 0
augustspies

run script if word/sentence found on website page?

14 posts in this topic

hey crew,

I just wanted to know if it's possible to search a webpage

for a specific word & or sentence and if found run a script

depending on the word/sentence.

ex.

if red found : run script 1

if blue found: run script 2

if possible where would I begin w/ the script

what items to look for in the help file

Thanks

Happy friday

Share this post


Link to post
Share on other sites



hey augustspies :huh2:,

Sure you can, search for _INetGetSource(), StringRegExp() in the helpfile ;)

Try cooking up something and post back if you're stuck. :alien:

Good luck,

-smartee

Share this post


Link to post
Share on other sites

great thanks for the reply smartee :huh2:

I tried the _INetGetSource() example however when it writes

to the console, some of the code had been stripped out which

is the part I need to search for.

would using:

- WinGetText

- ControlGetText

work?

Share this post


Link to post
Share on other sites

..when it writes

to the console, some of the code had been stripped out which

is the part I need to search for..

Perhaps you can post a little snippet so we can help you debug :huh2:

Share this post


Link to post
Share on other sites

The StringInStr function can also be used in this process. Like this:

If StringInStr(_INetGetSource($URL), $Text, 2) <> 0 Then ; true if $Text exists in $URL

; or

If StringInStr(_INetGetSource($URL), $Text, 2) = 0 Then ; true if $Text doesn't exist in $URL

thanks bruce your your input :huh2: Could you expand on what I do after the "then" statements?

Perhaps you can post a little snippet so we can help you debug ;)

thanks smartee, turns out I wasn't doing it right :alien:

I've attached what i've got so far.

- i'v used autoit's site for example purposes

- do you know how to grab a url from the browser window?

the url is always changing so I'm looking for a way to pull the url

then put it into the $url variable.

- the easy way i found would be to highlight the url

- copy to clipboard

- then paste into txt file

- have script read that file for url

- ? is that a good way?

- what would be my next step, once the word is searched.

if found/not found to trigger the running of script 1 or 2?

thanks for the help and time.

#include <INet.au3>

$url = "http://www.autoitscript.com/site/autoit/"
$findMe = "EXAMPLE"
$getSrcCode = _INetGetSource($url)


$location = StringInStr($getSrcCode, $findMe)
MsgBox(0, "Search result:", $location)

Share this post


Link to post
Share on other sites

thanks bruce your your input ;) Could you expand on what I do after the "then" statements?

You can do anything you want, when you want. :huh2:

#include <INet.au3>

$url = "http://www.autoitscript.com/site/autoit/"
$findMe = "EXAMPLE"

$location = StringInStr(_INetGetSource($url), $findMe)

If $location <> 0 Then
    MsgBox(0, "Search result:", "Exists: " & $location)
Else
    MsgBox(0, "Search result:", "Doesn't Exist: " & $location)
EndIf

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

You can do anything you want, when you want. :huh2:

#include <INet.au3>

$url = "http://www.autoitscript.com/site/autoit/"
$findMe = "EXAMPLE"

$location = StringInStr(_INetGetSource($url), $findMe)

If $location <> 0 Then
    MsgBox(0, "Search result:", "Exists: " & $location)
Else
    MsgBox(0, "Search result:", "Doesn't Exist: " & $location)
EndIf

lol, thanks bruce.

i'm running into the issue of not knowing how to set this up.

here's a basic example of where i'm at now:

there are 3 words to search for: red, white, blue

if red found run script 1

- red not found continue

if white found run script 2

- white not found continue

if blue found run script 3

- blue not found then exit

how would I set this up?

do I need to change the colors into a #?

would I need a loop? if so how would the loop look like.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

$sSrc = BinaryToString(InetRead($sURL))
$sCheck = StringRegExpReplace($sSrc, "(?is)^.+(red|white|blue).+$", "$1")
If @Extended Then
    Switch $sCheck
        Case "red"
            Run(and the details for script 1 in here)
        Case "white"
            Run(and the details for script 2 in here)
        Case "blue"
            Run(and the details for script 2 in here)
    EndSwitch
EndIf

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

$sSrc = BinaryToString(InetRead($sURL))
$sCheck = StringRegExpReplace($sSrc, "(?is)^.+(red|white|blue).+$", "$1")
If @Extended Then
    Switch $sCheck
        Case "red"
            Run(and the details for script 1 in here)
        Case "white"
            Run(and the details for script 2 in here)
        Case "blue"
            Run(and the details for script 2 in here)
    EndSwitch
EndIf

Thanks again bruce! I played around w/ it last night and early today

your script above works great. I ended up using it then trying something

different using stringInStr & if/else statements

here's what I came up w/:

func findMe ()
    $result = StringInStr($URL, "RED", 0)
    if $result > 0 then
        MsgBox(0,"Color Found", "Red")
    Else
        Exit 0
    EndIf
        
    $result = StringInStr($URL, "BLUE", 0)
    if $result > 0 then 
        MsgBox(0,"Color Found", "Blue")
    Else
        Exit 0
    EndIf
 EndFunc

thanks again bruce, smartee for your time and help

I really appreciate it.

Share this post


Link to post
Share on other sites

That's not my code that you're thanking me for.. but thanks for thanking me twice! :huh2:


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

IS any way how to find out location (X ,Y) of searched word ?

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

"Short answer: yes, with a maybe.  Long answer: no, with a but"

Using straight string searches would be difficult...you would need to use OCR, and get the Rect of your string, which may or may not be found, since it only grabs what is visible on screen.

If the string is nicely encapsolated in a dom object, then you can instead search for that object (_ie* functions), and then get the x/y coord of that object..._iepropertyget with browserx/browsery

If not nicely encapsolated, then you will need to (should do) still get the dom object, _IEAction "focus" on it (that brings it into view), then use the x/y/hight/width for the ocr, loop through the returned word objects, and get the rect of the word you need

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Hi somdcomputerguy,

The below code is working for non authenticated webpage. If I want to search a word in application which will ask for credentials while accessing, what code I should use?

#include <INet.au3>

$url = "http://www.autoitscript.com/site/autoit/"
$findMe = "EXAMPLE"

$location = StringInStr(_INetGetSource($url), $findMe)

If $location <> 0 Then
    MsgBox(0, "Search result:", "Exists: " & $location)
Else
    MsgBox(0, "Search result:", "Doesn't Exist: " & $location)
EndIf

 

Edited by Automationhc

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