getting text location
Moderators: Dorian (MJT support), JRL
-
- Newbie
- Posts: 13
- Joined: Tue May 18, 2010 6:54 pm
getting text location
hello,
I want to search a word that appears multiple times on the screen,
get the matches as in regex plus the coordinates of each match.
for example if the drawing is a text and I look the word "X" I want to get the number 4 and the cordinates of each "X":
------------X----------
--X--------------------
--------X--------------
------------------------
-----------------------
-----------------------
-----------------X----
is this possible?
I want to search a word that appears multiple times on the screen,
get the matches as in regex plus the coordinates of each match.
for example if the drawing is a text and I look the word "X" I want to get the number 4 and the cordinates of each "X":
------------X----------
--X--------------------
--------X--------------
------------------------
-----------------------
-----------------------
-----------------X----
is this possible?
find text on screen
Image recognition should be able to do it.
Also, what type of on-screen control is the text in? It's possible that GetControlText> can also read the text directly out of the control faster and with less chance of error.
Another technique I have used before is to (using keyboard commands) highlight the text and send it to the clipboard (using ctrl-c) and then retrieve the text from the clipboard into a variable and search it that way.
So you see there are many possibilities.
Also, what type of on-screen control is the text in? It's possible that GetControlText> can also read the text directly out of the control faster and with less chance of error.
Another technique I have used before is to (using keyboard commands) highlight the text and send it to the clipboard (using ctrl-c) and then retrieve the text from the clipboard into a variable and search it that way.
So you see there are many possibilities.
-
- Newbie
- Posts: 13
- Joined: Tue May 18, 2010 6:54 pm
image recognition
This still depends upon what you are going to do once you find the text. Now that I hear it is a webpage you have yet another way. You can simply retrieve the entire webpage using HTTPRequest> command and parse the returned HTML using RegEx> (regular expressions).what would be the easiest way?
Is this text in a hyperlink? Why do you want to know the screen coordinates? This could change depending upon the width/height of the browser window, etc. If you want to "click on the hyperlink" you don't need to know the screen coordinates, because you can do a "virtual click" by using the DOM (Document object model) and the browser using VBScript.
Not knowing the full details of what you want to do I would say you should start using image recognition. Read the help if you need to, then start putting together code and testing it. If you run into trouble, post the code you have written, as it's much easier to help when there is some code to look at instead of vague ideas.
Enjoy!
-
- Newbie
- Posts: 13
- Joined: Tue May 18, 2010 6:54 pm
well I've managed to solve the issue with image recognition, I only have 1 problem.
I use findimagepos which then creates an array of matching coordinates.
when I check a set of coordinates, like Xarr_1 and Yarr_1, I want to know if the next set after it, Xarr_2 and Yarr_2, have coordinates in them.
I used:
Assigned>xarr_1,result
and even though it has a number in it, I get returned FALSE in the result
why?
I use findimagepos which then creates an array of matching coordinates.
when I check a set of coordinates, like Xarr_1 and Yarr_1, I want to know if the next set after it, Xarr_2 and Yarr_2, have coordinates in them.
I used:
Assigned>xarr_1,result
and even though it has a number in it, I get returned FALSE in the result
why?
FindImagePos command returns the number of matches found
In the FindImagePos> command:FindImagePos>bitmap_to_find,bitmap_to_scan|SCREEN,color_tolerance,return_center,X_Array,Y_Array,NumFound
NumFound returns the number of matches found.
This should let you know how many array variables
have been created.
-
- Newbie
- Posts: 13
- Joined: Tue May 18, 2010 6:54 pm
well my solution failed.
I captured the text as an image and scanned the screen comparing it.
the problem is that sometimes all of the results don't appear in the same screen and I need to page down the webpage and repeat the scanning in order to get all the matches.
there is sometimes only a couple of lines more to the page and not a whole screen so the macro gets almost the same screen again with the same results and finds them again, doesnt know when to stop.
I captured the text as an image and scanned the screen comparing it.
the problem is that sometimes all of the results don't appear in the same screen and I need to page down the webpage and repeat the scanning in order to get all the matches.
there is sometimes only a couple of lines more to the page and not a whole screen so the macro gets almost the same screen again with the same results and finds them again, doesnt know when to stop.
Well, if scrolling the page is an issue I'd say you need to try these other
options:
options:
"Another technique I have used before is to (using keyboard commands) highlight the text and send it to the clipboard (using ctrl-c) and then retrieve the text from the clipboard into a variable and search it that way. "
"Retrieve the entire webpage using HTTPRequest> command and parse the returned HTML using RegEx> (regular expressions). "
-
- Newbie
- Posts: 13
- Joined: Tue May 18, 2010 6:54 pm
When I do Ctrl-A on a webpage it selects ALL the text without
me having to scroll the text into view. So this should work.
With the scrolling issue, I don't understand why you want to
know the coordinates on the screen since as I move the
scroll bars the text moves and so do all the coordinates.
They aren't fixed on the screen.
If it's so you can "click" on them, there are other ways to
accomplish that.
me having to scroll the text into view. So this should work.
With the scrolling issue, I don't understand why you want to
know the coordinates on the screen since as I move the
scroll bars the text moves and so do all the coordinates.
They aren't fixed on the screen.
If it's so you can "click" on them, there are other ways to
accomplish that.
-
- Newbie
- Posts: 13
- Joined: Tue May 18, 2010 6:54 pm
I'm trying to get the names of different products on a webpage.
the page is like tiles of products as you would in see in a typical webstore.
each "tile" looks like this:
///////////////
///////////////
////Picture///
///////////////
///////////////
Name of Product
Price:
Quantity:
I need to get each name seperately, because I do some processing on each name.
first I thought I'd try to recognize the pictures, but they constantly change so I tried just searching the whole page for the "Price:" because it's constant among all the tiles and then try to copy the name above it.
However this method doesn't have the ability to know which products it has already scanned (the problem I mentioned earlier), so I'm stuck.
the page is like tiles of products as you would in see in a typical webstore.
each "tile" looks like this:
///////////////
///////////////
////Picture///
///////////////
///////////////
Name of Product
Price:
Quantity:
I need to get each name seperately, because I do some processing on each name.
first I thought I'd try to recognize the pictures, but they constantly change so I tried just searching the whole page for the "Price:" because it's constant among all the tiles and then try to copy the name above it.
However this method doesn't have the ability to know which products it has already scanned (the problem I mentioned earlier), so I'm stuck.
parse HTML with RegEx
I think you need to parse the HTML. If you know nothing about HTML,
then you will after finishing this excercise!
Just to get an ideal of what you are facing, when the page is loaded
in your browser, do View->Source (If in IE... Firefox is similar)
and look at the actual HTML code. If you are lucky it is mostly
HTML without a lot of javascript functions doing stuff.
When implemented this way it is very reliable. The only way it can
break is if the author of the web page makes drastic changes to the
code. If the site is modern and uses CSS for formatting, the HTML
is even simpler, and when the author makes changes to the CSS to
change how it looks, it doesn't change the HTML.
You would use HTTPRequest> command to read in all the HTML
into a variable, and then start parsing it. RegEx is the best, but you
might be able to use Position> and MidStr> to accomplish your goal.
then you will after finishing this excercise!
Just to get an ideal of what you are facing, when the page is loaded
in your browser, do View->Source (If in IE... Firefox is similar)
and look at the actual HTML code. If you are lucky it is mostly
HTML without a lot of javascript functions doing stuff.
When implemented this way it is very reliable. The only way it can
break is if the author of the web page makes drastic changes to the
code. If the site is modern and uses CSS for formatting, the HTML
is even simpler, and when the author makes changes to the CSS to
change how it looks, it doesn't change the HTML.
You would use HTTPRequest> command to read in all the HTML
into a variable, and then start parsing it. RegEx is the best, but you
might be able to use Position> and MidStr> to accomplish your goal.
sample of website parsing using HTTPRequest
Here is a little sample I just made in 10 minutes to get you started.
[code]
Input>zip_code,Enter a zipcode to find out the current weather
Let>URL=http://www.briansutton.com/wx/weather.h ... s&#current
HTTPRequest>URL,,GET,,HTMLResponse
Let>String1=
Let>String2=
Length>String1,String1_length
Position>String1,HTMLResponse,1,StartAt
Add>StartAt,String1_length
Position>String2,HTMLResponse,StartAt,EndAt,FALSE
Let>myLen=EndAt-StartAt
MidSTr>HTMLResponse,StartAt,myLen,myWeather
MessageModal>The current weather for zipcode %zip_code% is %CRLF%%CRLF%%myWeather%
[/code]
[code]
Input>zip_code,Enter a zipcode to find out the current weather
Let>URL=http://www.briansutton.com/wx/weather.h ... s&#current
HTTPRequest>URL,,GET,,HTMLResponse
Let>String1=
Let>String2=
Length>String1,String1_length
Position>String1,HTMLResponse,1,StartAt
Add>StartAt,String1_length
Position>String2,HTMLResponse,StartAt,EndAt,FALSE
Let>myLen=EndAt-StartAt
MidSTr>HTMLResponse,StartAt,myLen,myWeather
MessageModal>The current weather for zipcode %zip_code% is %CRLF%%CRLF%%myWeather%
[/code]
-
- Newbie
- Posts: 13
- Joined: Tue May 18, 2010 6:54 pm
I don't think you fully understand my purpose.
I need to deal with each product name seperately. I first copy the name, paste it in another webpage, get a result, and the result I paste in the "Price" field. Parsing the entire HTML and using regex won't help me because I need to know the location on screen of every name, so I can paste the corresponding result of the name in its appropriate field.
I believe image recognition is the way here, but I can't find a way for the macro to "remember" which images he already scanned.
I need to deal with each product name seperately. I first copy the name, paste it in another webpage, get a result, and the result I paste in the "Price" field. Parsing the entire HTML and using regex won't help me because I need to know the location on screen of every name, so I can paste the corresponding result of the name in its appropriate field.
I believe image recognition is the way here, but I can't find a way for the macro to "remember" which images he already scanned.
HTTPRequest has a POST method for updating web pages also
You never mentioned about needing to update fields
in a webpage before...
No matter, HTTPRequest> has a POST method also
This means that you possibly DO NOT need a web browser at
all to accomplish your task. You parse page 1, get the field you
are after, do another HTTPRequest to page 2, parse the result
and then POST the result to page 3 (which updates it the same
as if you had typed it in and clicked whatever button you need
to)
You should have found my example for Weather exciting
Now you need to study how to do a POST method to a webpage.
in a webpage before...
No matter, HTTPRequest> has a POST method also
This means that you possibly DO NOT need a web browser at
all to accomplish your task. You parse page 1, get the field you
are after, do another HTTPRequest to page 2, parse the result
and then POST the result to page 3 (which updates it the same
as if you had typed it in and clicked whatever button you need
to)
You should have found my example for Weather exciting
Now you need to study how to do a POST method to a webpage.