augustspies Posted June 3, 2011 Posted June 3, 2011 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
smartee Posted June 3, 2011 Posted June 3, 2011 hey augustspies , Sure you can, search for _INetGetSource(), StringRegExp() in the helpfile Try cooking up something and post back if you're stuck. Good luck, -smartee
somdcomputerguy Posted June 3, 2011 Posted June 3, 2011 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 - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
augustspies Posted June 3, 2011 Author Posted June 3, 2011 great thanks for the reply smartee 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?
smartee Posted June 4, 2011 Posted June 4, 2011 ..when it writesto the console, some of the code had been stripped out whichis the part I need to search for..Perhaps you can post a little snippet so we can help you debug
augustspies Posted June 6, 2011 Author Posted June 6, 2011 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 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 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)
somdcomputerguy Posted June 6, 2011 Posted June 6, 2011 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. #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.
augustspies Posted June 7, 2011 Author Posted June 7, 2011 You can do anything you want, when you want. #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.
GEOSoft Posted June 7, 2011 Posted June 7, 2011 (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 June 7, 2011 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!"
augustspies Posted June 7, 2011 Author Posted June 7, 2011 $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.
somdcomputerguy Posted June 8, 2011 Posted June 8, 2011 That's not my code that you're thanking me for.. but thanks for thanking me twice! - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
crazyman Posted May 21, 2013 Posted May 21, 2013 IS any way how to find out location (X ,Y) of searched word ?
jdelaney Posted May 21, 2013 Posted May 21, 2013 (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 May 21, 2013 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.
Automationhc Posted May 19, 2015 Posted May 19, 2015 (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 May 19, 2015 by Automationhc
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now