Jump to content

HOW DO I SCAN FOR AN IMAGE ON A PAGE?


 Share

Recommended Posts

Link to comment
Share on other sites

whats it mean if i missed a seperator? here is code so far:

Local $coords

While 1

$coords = PixelSearch (0, 60, @DesktopWidth - 1024, @DesktopHeight - 639, Hexcolorhere, Shadevariationherecoulduse0XFFFFFF) ; that would search the whole screen for the pixel.

If @Error Then

Else

MouseClick('left', $Coords[792], $Coords[581], 1, 0)

EndIf

what should i change?

Link to comment
Share on other sites

whats it mean if i missed a seperator? here is code so far:

Local $coords

While 1

$coords = PixelSearch (0, 60, @DesktopWidth - 1024, @DesktopHeight - 639, Hexcolorhere, Shadevariationherecoulduse0XFFFFFF) ; that would search the whole screen for the pixel.

If @Error Then

Else

MouseClick('left', $Coords[792], $Coords[581], 1, 0)

EndIf

what should i change?

CODE
Local $coords

While 1

$coords = PixelSearch (0, 0, @DesktopWidth - 1024, @DesktopHeight - 639, 0XFFFFFF, 0, 0) ; it will search whole screen for anything BLACK, then click it...

If @Error Then

Else

MouseClick('left', $Coords[0], $Coords[1], 1, 0) ; do not change this

EndIf

Wend

Or, if you have AIM. Just IM me: Bluetigerprd

...

And yes, you could use _IE commands, which would be more efficient, but i'm a noob with those. You would need a more experienced Autoit user to help with that.

Edited by Writeous

[center][/center]

Link to comment
Share on other sites

#include <IE.au3>

HotKeySet("{ESC}", "terminate")

$site = "www.google.com"

;you want to find an image, so its  likely going to have certain info
;firebug is a firefox addon which lets you navigate the DOM (document object model)
;once you find a unique identifier for the button you want to press, do like this..

;here are some example calls to the DOM

;this is what google's main search box looks like
;<input value="" title="Google Search" size="55" name="q" maxlength="2048"/>


;we'll write a generalized function to search for elements with unique attributes
;for instance, there are two attributes that look unique, name="q" and title="Google Search".. 
;both of these are not likley to be found in a different input
Func find_by_attr($ie, $tag, $attribute, $text)
    $temp_ie = _IEDocGetObj($ie)
    
;get all the DOM elements with tag input (for instance) ... those are the ones that look like  <input value=""....
    $elements = $ie.document.getElementsByTagName($tag)
;parse the elements for the one your looking for, there might be more than one, look at IE.AU3 for some similar functions which allow you to specify an index
    For $element in $elements
    ;MsgBox(0, "", $element.getAttribute($tag))
        $my_attribute = $element.getAttribute($attribute)
        
        If $my_attribute = $text Then ;this is an exact match, use   StringInStr($my_attribute, $text) for substring matching
            return $element
        EndIf
    Next
EndFunc

;an example call will look like this
; find_by_attr($ie, "img", "alt", "Submit") ;will find the first image element with  alt="Submit"
; or for the example I gave with google, you could do it like this:
;find_by_attr($ie, "input", "name", "q")

;if your object has an ID, its really easy to access, as IDs MUST be unique. Names are not neccesarily unique though. An object can have an ID and a Name.
;$ie.document.getElementById("gbar");gets the gbar at the top of google.com



;now that you have the element, you need to click on it, this can be done by finding its position
; if the position is off the page, you'll need to write a function which detects it, and then scrolls down appropriately
; IE uses something like $ie.scrollTop and $ie.scrollLeft i believe, i'd need to double check, but i'm not going to if you don't need it

;so lets write a function to find the object on the screen, and another one to click it:

func locate_center($object)
     $top = _IEPropertyGet($object, "screeny")
     $left = _IEPropertyGet($object, "screenx")
     $width = _IEPropertyGet($object, "width")
     $height =_IEPropertyGet($object, "height")
     
    ;xy coords of the CENTER of the object
     Dim $coords[2] = [ $left + $width / 2, $top + $height / 2]
     
     return $coords
EndFunc

;now you can write a mouse function to move the mouse over the object and click it,
;this simulates exactly what a user would do

func move($object, $click = 1)  
;extra protection:
    if not IsObj($object) Then
        MsgBox(0, "", "failed to find object")
        terminate()
    EndIf

    $center = locate_center($object)
    
    MouseMove($center[0], $center[1])
    if( $click = 1) Then
        MouseClick("left")
    EndIf
EndFunc

main()

Func main()
    $ie = _IECreate($site)

    move(find_by_attr($ie, "input", "name", "q"), 1)
    Send("AutoIt Rocks")
    Send("{ENTER}")
    
EndFunc





func terminate()
    exit
EndFunc

hope this helps

you'll need IE to do this, maybe version 7 i don't know, but you get the idea

you can look at the IE.au3 files for more control

if you don't want to get firebug, just click 'view source' on your browser, and find out what unique identifiers your button has.

you don't need to search for it if it has an ID, or if its the only one if its kind, just do something like

$ie.document.getElementById("Submit_Button")

or if you know, for instnace that its the 4th input box in the 2nd form on the page what you can do is this:

$ie.document.getEelementsByTagName("form").item(3).getElementsByTagName("input").item(2)

notice, the arrays are 0-indexed

this is probably more control than you need, but it may come in use for other ppl

You'll have to write a loop with a 15 minute timer or whatever and call the find function each time

while true
    sleep(900000);15min
    
    $testobj = find_by_attr($ie, "input", "name", "q")

    if isObj($testobj) then
          move($testobj);click on it, or do whatever else....
                 ;you can test if it moved to a different page by using $ie.locationURL or something
                  ;for instnace   if StringInStr($ie.locationURL, "www.google.com") then <do stuff> endif
    endif
wend
Link to comment
Share on other sites

this is my current code

Local $coords

While 1

$coords = PixelSearch (0, 0, @DesktopWidth - 1024, @DesktopHeight - 768, Hexcolorhere, Shadevariationherecoulduse0X8FBEFF, 793, 663) ; that would search the whole screen for the pixel.

If @Error Then

Else

MouseClick('left', $Coords[0], $Coords[1], 1, 0)

EndIf

still says im missing a seperator on line 4

Edited by DaBoSS
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...