Jump to content

Searching for some text in a chrome web page


Recommended Posts

Hey guys,

 

Im new in autoit and the community and ive started using autoit for my work in order to automate some of the tasks that i need to do. while ive managed so far on my own as a newbee now im in need of a little help. 

what i need is this : in a chrome webpage ( local work page ) i need to search for a value ( its the start time of an event ) and its in HH:MM format ( usually 05:30 . 23:30 or 20:00 ). What i need to do is search for these predefined times and depending on which of them the page holds i need to enter a value in an empty field thats on the bottom of the page somewhere.

 

Ive been trying to use ControlGetText , WinGetText , etc but i just cant figure out where im wrong. 

 

The window is the active one btw and the field on the bottom i can just go to with the basic mouseclick command as it never changes position.

 

i was thinking that it could be done more complicated by selecting all the text in the page with a ctrl a , copy pasting it in a notepad and then just reading through that notepad to see what start time is mentioned but im sure there has to be an easier way.

 

 

Thanks in advance!

Link to comment
Share on other sites

Hi @MrDjBthu, and welcome to the AutoIt forum :)

There are a lot of Browser UDF, useful to automate Browser stuffs ( IE, Chrome, FireFox... ).

If you can use IE instead of Chrome, I suggest you to use _IE* functions, which are very reliable and easy to use.

Hope that helps :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

ive seen those IE functions but using IE is really ... hard ... and taking a toll on my nerves ...

 

so this has to be something browser specific, otherwise autoit cannot simply read from the screen regardless of the program used ? ive been reading around other topics around here and there were users with all sorts of software that they were using. i would have thought that for a browser it would be easier.

 

im really starting to consider copy pasting all in a notepad and just sorting it there and closing it after. problem is that i need to do this for 50+ page and not just one but should still be doable.

 

 

thank you for the help man!

Link to comment
Share on other sites

I don't know where you see that _IE functions are so hard, especially for the simple task you are trying to do...

Simply:

  • Create the IE Object with _IECreate(yourwebpage);
  • If the data you are looking for has an ID or a specific name, you could use _IEGetObjById() or _IEGetObjByName();
  • If it doesn't, then you could use _IEDocReadHTML() or _IEBodyReadHTML() to read the entire webpage or the body of it and search the value with StringRegExp() or StringInStr();
  • Write the value you want to write using the other _IE* functions.

I bet you won't get over 100 script rows :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

3 hours ago, MrDjBthu said:

i was thinking that it could be done more complicated by selecting all the text in the page with a ctrl a , copy pasting it in a notepad and then just reading through that notepad to see what start time is mentioned but im sure there has to be an easier way.

Hi MrDjBthu. I did this often with Opera Browser but without using NotePad or any manual search.

Let your script send Ctrl-a (select all), then Ctrl-c (copy to clipboard), finally $sPageContent = ClipGet()

Now let the script search anything you want inside the variable  $sPageContent
 

Edited by pixelsearch
Link to comment
Share on other sites

owww man this is a great idea! basically the shortcut of my copying into the notepad and it saves me the trouble of opening said notepad and closing it, which would not have taken that much time but would have been onscreen and somewhat annoying.

 

but if this works its perfect, get all the clipboard text into the $sPageContent and then just do a search ( need to figure out a tidy logical way to jungle around all my start times and what these will trigger ) in it for what i need.

 

thanks man, excellent idea!

Link to comment
Share on other sites

owww man this is a great idea! basically the shortcut of my copying into the notepad and it saves me the trouble of opening said notepad and closing it, which would not have taken that much time but would have been onscreen and somewhat annoying.

 

but if this works its perfect, get all the clipboard text into the $sPageContent and then just do a search ( need to figure out a tidy logical way to jungle around all my start times and what these will trigger ) in it for what i need.

 

thanks man, excellent idea!

 

 

later edit : 

got it! 

 

MouseClick("left", 1370, 940)
Send("^a")
Sleep( 1000 )
Send("^c")
Sleep( 1000 )
$sPageContent = ClipGet()
$searchstring1 = "05:30"
If StringInStr($sPageContent, $searchstring1) Then
   MouseClick("left", 370, 940)
   Send("11")

 

that was what i needed! now i need to tweak it to add the other times and thens. 

 

cheers man!

Link to comment
Share on other sites

aaaaaand im stuck again. keep trying to get all my star times together but im getting this message that im missing a Next on line 37.

What am i doing wrong ?

 

#include <MsgBoxConstants.au3>

MouseClick("left", 1370, 940)
Send("^a")
Sleep( 1000 )
Send("^c")
Sleep( 1000 )
$sPageContent = ClipGet()
$searchstring11 = "04:30"
$searchstring12 = "05:30"
$searchstring13 = "06:00"
$searchstring22 = "23:30"
$searchstring23 = "00:30"
$searchstring24 = "23:00"
$searchstring33 = "20:00"
$searchstring34 = "15:30"
$searchstring35 = "16:30"
$searchstring36 = "17:30"
$searchstring37 = "18:00"

   For $i = 11 to 13
      If StringInStr($sPageContent, $searchstring[$i]) Then
   MouseClick("left", 370, 940)
   Send("11")
      Else
   For $j = 22 to 24
      If StringInStr($sPageContent, $searchstring[$j]) Then
   MouseClick("left", 370, 940)
   Send("3")
      Else
   For $k = 33 to 37
      If StringInStr($sPageContent, $searchstring[$k]) Then
   MouseClick("left", 370, 940)
   Send("6")
      EndIf
   Next
      Sleep ( 13000 )

 

Link to comment
Share on other sites

As Francesco noticed it, 2 EndIf + 2 Next were missing :)

Also, variable $searchstring37 (for example) will not be accessible thru array $searchstring[$i] even when $i = 37, you'll have to work with Arrays from the beginning. What about this ?
 

Global $searchstring[38]    ; from 0 to 37

$searchstring[11] = "04:30 - 11"
$searchstring[12] = "05:30 - 11"
$searchstring[13] = "06:00 - 11"

$searchstring[22] = "23:30 - 3"
$searchstring[23] = "00:30 - 3"
$searchstring[24] = "23:00 - 3"

$searchstring[33] = "20:00 - 6"
$searchstring[34] = "15:30 - 6"
$searchstring[35] = "16:30 - 6"
$searchstring[36] = "17:30 - 6"
$searchstring[37] = "18:00 - 6"

MouseClick("left", 1370, 940)
Send("^a")
Sleep( 1000 )
Send("^c")
Sleep( 1000 )
$sPageContent = ClipGet()

For $i = 11 to 37
   If $searchstring[$i] <> "" Then
      If StringInStr($sPageContent, StringLeft($searchstring[$i],5)) Then
         $SendMe = StringMid($searchstring[$i], 9) ; will send 11 or 3 or 6
         MouseClick("left", 370, 940)
         Sleep( 1000 )
         Send($SendMe)
         Sleep( 1000 )
         ExitLoop
      EndIf
   EndIf
Next

Please tell us if it worked :)

 

Link to comment
Share on other sites

hi again and thanks for another answer pixelsearch!

 

like i said im quite a beginner here so pretty much im just winging it with the code. i did manage to get it working though its something that a neanderthal would write ( as code ) :

$sPageContent = ClipGet()
$searchstring11 = "05:30"
$searchstring12 = "04:30"
$searchstring13 = "06:00"
$searchstring22 = "23:30"
$searchstring23 = "00:30"
$searchstring24 = "23:00"
$searchstring33 = "20:00"
$searchstring34 = "15:30"
$searchstring35 = "16:30"
$searchstring36 = "17:30"
$searchstring37 = "18:00"

If StringInStr($sPageContent, $searchstring11) Then
   MouseClick("left", 370, 995)
   Send("11")
   ElseIf StringInStr($sPageContent, $searchstring12) Then
   MouseClick("left", 370, 995)
   Send("11")
   ElseIf StringInStr($sPageContent, $searchstring13) Then
   MouseClick("left", 370, 995)
   Send("11")
ElseIf StringInStr($sPageContent, $searchstring33) Then
   MouseClick("left", 370, 995)
   Send("6")
   ElseIf StringInStr($sPageContent, $searchstring34) Then
   MouseClick("left", 370, 995)
   Send("6")
   ElseIf StringInStr($sPageContent, $searchstring35) Then
   MouseClick("left", 370, 995)
   Send("6")
   ElseIf StringInStr($sPageContent, $searchstring36) Then
   MouseClick("left", 370, 995)
   Send("6")
   ElseIf StringInStr($sPageContent, $searchstring36) Then
   MouseClick("left", 370, 995)
   Send("6")
ElseIf StringInStr($sPageContent, $searchstring22) Then
   MouseClick("left", 370, 995)
   Send("3")
   ElseIf StringInStr($sPageContent, $searchstring23) Then
   MouseClick("left", 370, 995)
   Send("3")
   ElseIf StringInStr($sPageContent, $searchstring24) Then
   MouseClick("left", 370, 995)
   Send("3")
   Sleep ( 1000 )
EndIf

 

and looking at what you wrote i first need to figure out what that exactly does / translate it into something that i can think with/about.

basically youve added the - 11 , - 6 and - 3 into my predefined strings that i would be searching for , but when doing the actual search you are only searching the first 5 characters and if the search finds something you tell it to sendus whats after character 9 in our predefined strings, correct ?

 

im not exactly sure what this if does : 

If $searchstring[$i] <> "" Then

im guessing its meant to keep the For above going and increment the $i so that it passes through all our searchstrings ?

 

 

ill give this  a try tomorrow when at work and will let you know. as right now im beat and the only thing i want is to open a beer and relax for the rest of the evening.

 

again, much appreciated man!

Link to comment
Share on other sites

Hi MrDjBthu,
All your guesses about my code are correct, especially the :
 

If $searchstring[$i] <> "" Then

It allows the script to quickly ignore the empty elements in the Array, like $searchstring[14] for example (which contains nothing), while keeping increment $i in the For... Next loop
Now enjoy your beer(s) and have a great evening, see you tomorrow :)
 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...