[..] Automatiser un copier/coller chrome vers un programme

Aide et conseils concernant AutoIt et ses outils.
Règles du forum
.
Répondre
Avatar du membre
phil01
Niveau 1
Niveau 1
Messages : 4
Enregistré le : mer. 14 mai 2014 16:09
Localisation : Luxembourg
Status : Hors ligne

[..] Automatiser un copier/coller chrome vers un programme

#1

Message par phil01 »

Salut je suis entrain de me réaliser un petit scripte pour lancer un site sur chrome, skip les pubs, copier le texte et coller dans un programme
Et cela sera lancer sur mon serveur un fois par jour je le ferais probablement a l'aide d'un Scheduler

Voila je suis assez novice en programmation et j'aurais besoin de conseille ou d'un rappel d'oublie
Le scripte fonctionne mais je crois que visuellement c'est pas trop ça

Et j'avoue avoir fait du copie coller d'autre scripte trouver sur internet.

Code : Tout sélectionner

Global $site = ""
Global $copy = ""
Global $try = ""
ClipPut("") ;Clear the clipboard, so we can check for data when we write to it
Global $textcheck = "" ;We'll put new clipboard data in this variable
Global $Paused
HotKeySet("{ESC}", "Terminate")

Func _WinWaitActivate($title,$text,$timeout=0)
    WinWait($title,$text,$timeout)
    If Not WinActive($title,$text) Then WinActivate($title,$text)
    WinWaitActive($title,$text,$timeout)
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func Site()
    ShellExecute("chrome.exe", "http://xxxxxxxxx1","","")
;~  ShellExecute("chrome.exe", "http://xxxxxxxxx2","","")
    _WinWaitActivate("[CLASS:Chrome_WidgetWin_1]","", 5)

    Sleep(5000)

    WinSetState("[CLASS:Chrome_WidgetWin_1]", "",@SW_MAXIMIZE)
EndFunc

Func PUB()
    While  WinExists("Oops! Google Chrome could not find xxxxxxxxx1 - Google Chrome","") or WinExists("Oops! Google Chrome could not find xxxxxxxxx2 - Google Chrome","") or WinExists("Félicitations! - Google Chrome","") or WinExists("AdF.ly - shrink your URLs and get paid! - Google Chrome") or WinExists("LinkBucks.com - Get your share! - Google Chrome","") or WinExists("AdFly - The URL shortener service that pays you! Earn money for every visitor to your links. - Google Chrome","")
        If WinExists("Oops! Google Chrome could not find xxxxxxxxx1 - Google Chrome","") or WinExists("Oops! Google Chrome could not find xxxxxxxxx2 - Google Chrome","") Then
            MouseClick("left",81,48,1) ;Refresh
            Sleep(5000)
            $try += 1
        EndIf
        if WinExists("Félicitations! - Google Chrome","") then
            MouseClick("left",1663,12,1)
            Sleep(5000)
            $try += 1
        EndIf
        if WinExists("AdF.ly - shrink your URLs and get paid! - Google Chrome") then
            Sleep(7500)
            MouseClick("left",1546,100,1) ;Skip Adf.ly
            Sleep(5000)
            $try += 1
        EndIf
        If WinExists("LinkBucks.com - Get your share! - Google Chrome","") Then
            Sleep(6500)
            MouseClick("left",1627,90,1) ;Skip LinkBucks.com
            Sleep(5000)
            $try += 1
        EndIf
        If WinExists("AdFly - The URL shortener service that pays you! Earn money for every visitor to your links. - Google Chrome","") Then
            MouseClick("left",127,20,1) ;Click first tab
            $try += 1
        EndIf
        if $try = 5 Then ;if 5 trys relaunch site
            Site()
        EndIf
    WEnd
EndFunc

Func copy_check()


    ;Get window title, in case we need it
    $window_title = WinGetTitle("[active]")

    if $window_title == "" Then
        SoundPlay(@WindowsDir & "\media\Windows XP Error.wav",1)
        Exit
    EndIf


    WinActivate($window_title)


    ClipPut("") ;Clear the clipboard, so we can check for data when we write to it
    $readtext = "" ;We'll put new clipboard data in this variable

    For $i = 1 to 8 Step 1

        $rand = random (1, 4, 1)

        Send ("{CTRLDOWN}")
        ;Try various methods until we get text on the clipboard
        Switch $rand
            Case 1
                Send("{INS}")
            Case 2
                ControlSend($window_title, "", "", "{INS}")
            Case 3
                Send("c")
            Case 4
                ControlSend($window_title, "", "", "c^")
        EndSwitch

        Send ("{CTRLUP}")
        $readtext = ClipGet() ;Any text on the clipboard?
        If $readtext <> "" Then
            Sleep(ToolTip('Text copied with success', 780, 480, '', Default, Default)*0+1000)
            return $readtext
        EndIf

        If $i = 4 Then
            WinActivate($window_title)
            Sleep(100)
        EndIf

    Next

    return $readtext

EndFunc


Site()
PUB()


If  WinExists("xxxxxxxxx1 - Google Chrome") or WinExists("xxxxxxxxx2 - Google Chrome") then
    While 1
        Sleep(50)
        MouseClick("left",116,263,1) ;Click on page to check Ads
        PUB()
        If  WinExists("xxxxxxxxx1 - Google Chrome") then
            Sleep(2000)
            PUB()
            Sleep(1500)
            PUB()
            Sleep(1000)
            PUB()
            WinWaitActive("xxxxxxxxx1 - Google Chrome")
            Local $site = "xxxxxxxxx1"
        ElseIf WinExists("xxxxxxxxx2 - Google Chrome") then
            Sleep(2000)
            PUB()
            Sleep(1500)
            PUB()
            Sleep(1000)
            PUB()
            WinWaitActive("xxxxxxxxx2 - Google Chrome")
            Local $site = "xxxxxxxxx2"
        EndIf
        If  WinExists("xxxxxxxxx1 - Google Chrome") or WinExists("xxxxxxxxx2 - Google Chrome") then
            Sleep(3500)
            MouseClick("left",838,504,1) ;Click 1
            MouseClick("left",855,580,1) ;Click Entre
            Sleep(3000)
            MouseClickDrag ("left",1051,555,628,555) ;Select Text to copy
            copy_check()
            Local $copy = "paste"
        EndIf
        $textcheck = ClipGet()
        If $textcheck <> "" Then ExitLoop
    WEnd
EndIf

if $copy = "paste" Then
    WinSetState("[CLASS:Chrome_WidgetWin_1]", "",@SW_MINIMIZE) ;Minimize Chrome
    Sleep(50)
    ShellExecute("prog.exe")
    Sleep(50)
    WinActivate("prog")
    _WinWaitActivate("prog", "")
    Sleep(50)
    WinMove("prog", "", 0, 0)
    Sleep(50)
    ControlClick ( "prog", "", "[CLASS:TbsSkinButton; INSTANCE:2]" ) ;Click Edit
    if $site = "xxxxxxxxx1" Then
        MouseClickDrag("left",601,442,333,443) ;Select "xxxxxxxxx1" Text to paste
    ElseIf $site = "xxxxxxxxx2" Then
        MouseClickDrag("left",665,483,307,481) ;Select "xxxxxxxxx2" Text to paste
    EndIf
    Send("^v")
    ControlClick ( "prog", "", "[CLASS:TbsSkinButton; INSTANCE:5]" ) ;Click Save
    Sleep(50)
    _WinWaitActivate("prog","")
    ControlClick ( "prog", "", "[CLASS:TButton; INSTANCE:1]" ) ;Click OK
    _WinWaitActivate("prog","")
    ControlClick ( "prog", "", "[CLASS:TbsSkinButton; INSTANCE:4]" ) ;Click Exit
    Sleep(ToolTip('New Text was put in prog', 780, 480, '', Default, Default)*0+1000)
EndIf
Avatar du membre
TommyDDR
Modérateur
Modérateur
Messages : 2127
Enregistré le : mar. 22 juil. 2008 21:55
Localisation : Nantes
Status : Hors ligne

Re: [..] Automatiser un copier/coller chrome vers un program

#2

Message par TommyDDR »

1) Évitez les MouseClic dit "sauvages", optez pour un clic relatif à la position de la fenêtre sous peine de devoir changer toutes vos positions (regardez du côté de WinGetPos pour avoir la position de la fenêtre)
2)

Code : Tout sélectionner

Sleep(ToolTip('New Text was put in prog', 780, 480, '', Default, Default)*0+1000)
??
Vous avez un forfait au nombre de ligne utilisé ? :P

Code : Tout sélectionner

ToolTip('New Text was put in prog', 780, 480, '', Default, Default)
Sleep(1000)
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Avatar du membre
phil01
Niveau 1
Niveau 1
Messages : 4
Enregistré le : mer. 14 mai 2014 16:09
Localisation : Luxembourg
Status : Hors ligne

Re: [..] Automatiser un copier/coller chrome vers un program

#3

Message par phil01 »

Évitez les MouseClic dit "sauvages", optez pour un clic relatif à la position de la fenêtre sous peine de devoir changer toutes vos positions (regardez du côté de WinGetPos pour avoir la position de la fenêtre)
Si j'ai bien compris ça devrait s’écrire comme ci-dessous

Code : Tout sélectionner

MouseClickDrag("left",601,442,333,443)
MouseClick("left",116,263,1)
devient

Code : Tout sélectionner

$WinPos = WinGetPos("prog")
MouseClick("left",$WinPos[0] + 116,$WinPos[1] + 263,1)
MouseClickDrag("left",$WinPos[0] + 601,$WinPos[1] + 442,$WinPos[0] + 333,$WinPos[1] + 443)
Si c'est ça je sais comment m'y prendre pour le programme
Mais sur Chrome je bloque un peu est-ce que je dois faire un $WinPos pour chaque titre :?:
Vous avez un forfait au nombre de ligne utilisé ? :P
Non :lol:
C'est ce que j'ai trouvé sur le net
Je vais utiliser comme vous l'avais écrit ça me fait moins mal aux yeux :)
Avatar du membre
TommyDDR
Modérateur
Modérateur
Messages : 2127
Enregistré le : mar. 22 juil. 2008 21:55
Localisation : Nantes
Status : Hors ligne

Re: [..] Automatiser un copier/coller chrome vers un program

#4

Message par TommyDDR »

Il vous faudra en effet fait un $wPos pour chaque coordonnée.
Après, rien de vous empêche de mettre $wPos en global et de "surcharger" les fonctions, par exemple :

Code : Tout sélectionner

Func MouseClickChrome($button, $x = Default, $y = Default, $clics = 1, $speed = 10)
    MouseClick($button, $x+$wPos[0], $y+wPos[1], $clics, $speed)
EndFunc
Et de remplacer tous vos appels à MouseClick par des appels à MouseClickChrome.
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
Répondre