ruslanas402

Open webpages by checking boxes

11 posts in this topic

Hello everyone, don't even know how to ask.  My code is:

#include <String.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 700, 500, 192, 124)
$Button1 = GUICtrlCreateButton("View", 576, 24, 89, 41)

Global $oIE = _IECreate("https://www.youtube.com/playlist?list=PL4Jcq5zn02jKpjX0nqI1_fS7mEEb5tw6z", 1, 1, 0)
Sleep(1000)
Global $sHTML = _IEDocReadHTML($oIE)
$FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner')
$x = 16
For $a In $FirstChunks
   $actualdata = _StringBetween($a, '">', '</a>')
   ;$actualdata2 = _StringBetween($a, 'href="', '&amp;')
   $Checkbox1 = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)
   $x = $x + 20
Next

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Somehow I need to open webpages where checkbox is checked by presing button view, I think I need somehow asign $actualdata with $actualdata2. Any ideas would be very appreciated :)

Share this post


Link to post
Share on other sites



I think I'm not the first person with this issue, it has to be solved somewhere already. Just give me some links please :)

Share this post


Link to post
Share on other sites

Little impatient? :)

Store the handles in that loop into an Array like:

$Checkbox[$a] = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)

And then do a For..Next in the Message loop check for any of these handles. This is also done in this way in SciTEConfig.au3 that comes with the full version of SciTE4AutoIt3.

Jos 

1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

40 minutes ago, Jos said:

Little impatient? :)

Store the handles in that loop into an Array like:

$Checkbox[$a] = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)

And then do a For..Next in the Message loop check for any of these handles. This is also done in this way in SciTEConfig.au3 that comes with the full version of SciTE4AutoIt3.

Jos 

Hi Jos, I'm not just thought nobody will answer.  Thx for advice, but still I'm in dark.

$FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner')
Global $Checkbox1[100]
$x = 16
$a = 0
For $a In $FirstChunks
   $actualdata = _StringBetween($a, '">', '</a>')
   ;$actualdata2 = _StringBetween($a, 'href="', '&amp;')
   $Checkbox1[$a] = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)
   $x = $x + 20
   $a = $a + 1
Next

Am I going to right direction? I didn't uderstand what you meant by saying "Message loop check for any of these handles" :)

Edited by ruslanas402

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

12 minutes ago, ruslanas402 said:

$a = $a + 1

You don't want to do that as the For ... Next will fill $a with content. add another variable for the counting ($y).

Just redim your array to the correct number after the initial For...Next like:

$FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner')
Global $Checkbox1[100]
$x = 16
$y = 0
For $a In $FirstChunks
   $actualdata = _StringBetween($a, '">', '</a>')
   ;$actualdata2 = _StringBetween($a, 'href="', '&amp;')
   $Checkbox1[$a] = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)
   $x = $x + 20
   $y = $y + 1
Next
ReDim $Checkbox1[$y-1]

Then add something like this in your message loop:

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    ; check whether a button is pressed
    For $x = 0 to UBound($Checkbox1)-1
        If $nMsg = $Checkbox1[$x] Then
            ;  do what you want to do for Button pressed
        EndIf
    next
WEnd

 

Edited by Jos
1 person likes this

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
5 hours ago, Jos said:

;  do what you want to do for Button pressed

I'm giving up. My final best code

$Form1 = GUICreate("Form1", 700, 500, 192, 124)
$Button1 = GUICtrlCreateButton("View", 576, 24, 89, 41)
Global $oIE = _IECreate("https://www.youtube.com/playlist?list=PL4Jcq5zn02jKpjX0nqI1_fS7mEEb5tw6z", 1, 1, 0)
Sleep(1000)
Global $sHTML = _IEDocReadHTML($oIE)
$FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner')
Global $Checkbox1[200]
$x = 16
$y = 0
For $a In $FirstChunks
   $actualdata = _StringBetween($a, '">', '</a>')
   $actualdata2 = _StringBetween($a, 'href="', '&amp;')
   $Checkbox1[$a] = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)
   $x = $x + 20
   $y = $y + 1
Next
ReDim $Checkbox1[$y-1]

GUISetState(@SW_SHOW)
Sleep(1000)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    ; check whether a button is pressed
    For $x = 0 to UBound($Checkbox1)-1
        If $nMsg = $Checkbox1[$x] Then
            ;  do what you want to do for Button pressed
            _IECreate("www.youtube.com/" & $actualdata2)
        EndIf
    next
WEnd

But instead of opening selected boxes, it just opens "youtube.com" website constantly

Share this post


Link to post
Share on other sites

try

$_IECreate("www.youtube.com/" & $actualdata2[$x])

you can also insert a Consolewrite for checking the url:

ConsoleWrite("www.youtube.com/" & $actualdata2[$x]&@crlf)

you can also use _ArrayDisplay to see if the arrays: $FirstChunks, $actualdata and $actualdata2 has expected elements.

1 person likes this

Share this post


Link to post
Share on other sites

Nothing happens I think I should make variables $actualdata and $actualdata2 to 2D dimensional arrays, but HOW:?

So far my code:

#include <String.au3>
#include <IE.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 700, 500, 192, 124)
$Button1 = GUICtrlCreateButton("View", 576, 24, 89, 41)
Global $oIE = _IECreate("https://www.youtube.com/playlist?list=PL4Jcq5zn02jKpjX0nqI1_fS7mEEb5tw6z", 1, 1, 0)
Sleep(1000)
Global $sHTML = _IEDocReadHTML($oIE)
$FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner')
Global $Checkbox1[200]
$x = 16
$y = 0
For $a In $FirstChunks
   $actualdata = _StringBetween($a, '">', '</a>')
   $actualdata2 = _StringBetween($a, 'href="', '&amp;')
   $Checkbox1[$a] = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)
   $x = $x + 20
   $y = $y + 1
Next
ReDim $Checkbox1[$y-1]

GUISetState(@SW_SHOW)
Sleep(1000)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    ; check whether a button is pressed
    For $x = 0 to UBound($Checkbox1)-1
        If $nMsg = $Checkbox1[$x] Then
            ;  do what you want to do for Button pressed
            ConsoleWrite("www.youtube.com/" & $actualdata2[$x]&@crlf)
        EndIf
    next
WEnd

Try yourself mate, playlist isn't private :)

Share this post


Link to post
Share on other sites

Test this script:

#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <String.au3>
#include <Array.au3>

$Form1 = GUICreate("Form1", 700, 500, 192, 124)
$Button1 = GUICtrlCreateButton("View", 576, 24, 89, 41)
Global $oIE = _IECreate("https://www.youtube.com/playlist?list=PL4Jcq5zn02jKpjX0nqI1_fS7mEEb5tw6z", 1, 1, 0)
Sleep(1000)
Global $sHTML = _IEDocReadHTML($oIE)
$FirstChunks = _StringBetween($sHTML, 'pl-video-title-link yt-uix-tile-link yt-uix-sessionlink', '<div class="pl-video-owner')
;_ArrayDisplay($FirstChunks, '$FirstChunks')
Global $Checkbox1[UBound($FirstChunks)][2]
$x = 16
$y = 0
$iCheck = 0
For $a = 0 To UBound($FirstChunks) - 1
    $actualdata = _StringBetween($FirstChunks[$a], '">', '</a>')
    If Not IsArray($actualdata) Then ContinueLoop
    $actualdata2 = _StringBetween($FirstChunks[$a], 'href="', '&amp;')
    If Not IsArray($actualdata2) Then ContinueLoop
    $Checkbox1[$iCheck][0] = GUICtrlCreateCheckbox($actualdata[0], 24, $x, 500, 17)
    $Checkbox1[$iCheck][1] = $actualdata2[0]
    $iCheck += 1
    $x = $x + 20
    $y = $y + 1
Next
ReDim $Checkbox1[$iCheck][2] ;maybe some checkboxes aren't created (avoiding corupt data using ContinueLoop)
_ArrayDisplay($Checkbox1,'checkbox ids |URL-watchpart')
GUISetState(@SW_SHOW)
Sleep(1000)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ; check whether a button is pressed
            For $x = 0 To UBound($Checkbox1) - 1
                ConsoleWrite('X: ' & $x & @TAB & $Checkbox1[$x][0] & @TAB)
                If BitAND(GUICtrlRead($Checkbox1[$x][0]), $GUI_CHECKED) = $GUI_CHECKED Then
                    ConsoleWrite('is checked')
                    ;  do what you want to do for Button pressed
                    ConsoleWrite("www.youtube.com/" & $Checkbox1[$x][1] & @CRLF)
                    _IECreate("www.youtube.com/" & $Checkbox1[$x][1])
                    GUICtrlSetState($Checkbox1[$x][0], $GUI_UNCHECKED) ;so you have toc check again and press view
                    ExitLoop ;as you can't see all tut's at same time
                Else
                    ConsoleWrite('is not checked')
                EndIf
                ConsoleWrite('press View' & @CRLF)
            Next
    EndSwitch
WEnd

it should work like expected, but i can't test my internet is to poor (64 kbs).

1 person likes this

Share this post


Link to post
Share on other sites

You amazing man.  Thank you so much, it does exactly as I wanted I knew it should use two dimensional arays. :D Just couldn't figure out how to combine them. :) Sorry for internet connection  :P

Share this post


Link to post
Share on other sites
1 hour ago, ruslanas402 said:

You amazing man.

Glad i could help. :)

 

Share this post


Link to post
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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      Before all, I want to say that I'm doing this script to see how _IE* functions work, and see if my studs can hack a quiz I'm working on.
      I want to clarify that I'm not automating any game, bypassing any CAPTCHAs, or anything that could damage anyone.
      I was trying to autofill a form, based on which question is displayed.
      The question is always stored in here:
      <header> <h1><span class="questionid">1. </span>Here goes the question</h1> </header> And answers are stored in here:
      <ul class="answers"> <li><label><span><input id="answer_0" name="answer[]" type="radio" value="0">Answer 1</span></label></li> <li><label><span><input id="answer_1" name="answer[]" type="radio" value="1">Answer 2</span></label></li> <li><label><span><input id="answer_2" name="answer[]" type="radio" value="2">Anwser 3</span></label></li> <li><label><span><input id="answer_3" name="answer[]" type="radio" value="3">Answer 4</span></label></li> </ul></fieldset></form></div> And, there are 15 questions like this.
      How can automatically fill my form?
      Thanks in advance
      Francesco
    • Omnitica
      By Omnitica
      Hello!
      I'm new to the forums! Couldn't find any threads covering this issue. Sorry if I'm wrong.

      I'm having problems changing the text/value of a input box. The particular box doesn't have a name or id, just: class="jq_hotkeys_enabled form-control".
      This class appears multiple times throughout the source, so I don't think It's right to reference that object. 
      See image 1.
      However, I've managed to find a object with the name "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper" which contains the value of the input box, and the id for the person in the dropdown/combobox left of it. (with "dummy-1" selected).
      See image 2.
      As you can see the value is 3982,4545     ( name , time )
      But when I try to change the value of it by doing:
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") The box doesn't get its new value. I  can see in the source that it's changed though.
      See image 3.
       
      However, if I do: 
      #include <IE.au3> Local $oIE = _IEAttach(WinGetHandle("[CLASS:IEFrame]"),"embedded") Local $oForm = _IEFormGetObjByName($oIE, "aspnetForm") Local $oInput = _IEFormElementGetObjByName($oForm, "ctl00$content$ctrl$ucServiceTime$rpServicetimes$ctl00$edtHiddenResourceHelper") _IEFormElementSetValue($oInput, "3982,1337") $oIE.document.parentwindow.execScript("theForm.submit()") ; But it needs to reload the page The box gets its new value after the page reloads by the theForm.submit() function. 
      This is a bit unfortunate as I want the changes to happen instantly like when I type in the box with the keyboard... or select in the combobox.
      Maybe someone knows how I can do this? Looking forward to an answer! 
      Thanks in advance.
       
      Note: Unfortunately I can't provide with the real URL as it is constricted to employees in the company I work for, but let me know If I should provide anything else.
       



    • czardas
      By czardas
      Haven't had much time to code recently. However the following thread inspired me.
      The debate about linear, parallel and binary search methods was rather interesting and, in an attempt to be diplomatic, I decided to combine @jchd's suggestion with @LarsJ's binary search example. I decided that the binary search algorithm required modification to make it more linear. As usual, 'if you invent something, it probably already exists and if it already exists, it exists for a reason'. My first attempt was not all that good. The code worked but was really a mess. I blame peer pressure (to post an example of a parallel search method).  I will delete that old code in due course.
      With a little memory jogging and a glance at the help file, the solution turned out to be quite easy: I just needed a better understanding of Euler. Further modification will be needed to work with more complicated unicode strings. The output could be returned as an array or a delimitered string. I'm not so interested in those details. I'm just going to post the algorithm for now and anyone, who wants to, can modify it to suit their needs. Both arrays must contain at least 1 element.
      Local $aFoo = [0,1,2,3,4,5,6,7,9,10,11,12,13,14,15,16,19,20,23,24,26,30,35,39,40,41] Local $aBar = [0,1,5,6,7,8,9,10,11,12,13,14,17,18,19,21,24,25,26,27,34,35,38,40] ParallelExponetialSearch($aFoo, $aBar) ; Compares two lists - returning positive matches. Each input array must be unique (individually) and in alphabetical order. Func ParallelExponetialSearch($aFoo, $aBar) Local $sFind, _ $iMin_F = -1, $iMax_F = UBound($aFoo) -1, $Lo_F = $iMin_F, $Hi_F, _ $iMin_B = -1, $iMax_B = UBound($aBar) -1, $Lo_B = $iMin_B, $Hi_B While $iMin_F < $iMax_F And $iMin_B < $iMax_B ; Toggle Arrays - Which array has most untested elements? This is the one we want to search next, ; so we can bypass more comparisons because (in theory) mismatches have a greater chance of being skipped. If $iMax_F - $iMin_F >= $iMax_B - $iMin_B Then ; $aFoo has more (or an equal number of) untested elements $Hi_F = $iMax_F $iMin_B += 1 $sFind = $aBar[$iMin_B] While $Lo_F < $Hi_F ; search $aFoo For $i = 0 To Floor(Log($Hi_F - $Lo_F) / Log(2)) $Lo_F = $iMin_F + 2^$i If $aFoo[$Lo_F] = $sFind Then $iMin_F = $Lo_F ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $Lo_F & "] = $aBar[" & $iMin_B & "]" & @LF) ExitLoop 2 ElseIf $aFoo[$Lo_F] > $sFind Then $Hi_F = $Lo_F -1 $iMin_F += Floor(2^($i -1)) $Lo_F = $iMin_F ContinueLoop 2 EndIf Next $iMin_F = $Lo_F ; minimum increment is one WEnd Else ; $aBar has more untested elements $Hi_B = $iMax_B $iMin_F += 1 $sFind = $aFoo[$iMin_F] While $Lo_B < $Hi_B ; search $aBar For $i = 0 To Floor(Log($Hi_B - $Lo_B) / Log(2)) $Lo_B = $iMin_B + 2^$i If $aBar[$Lo_B] = $sFind Then $iMin_B = $Lo_B ; each match should be added to the output [perhaps an array] ConsoleWrite($sFind & " found at $aFoo[" & $iMin_F & "] = $aBar[" & $Lo_B & "]" & @LF) ExitLoop 2 ElseIf $aBar[$Lo_B] > $sFind Then $Hi_B = $Lo_B -1 $iMin_B += Floor(2^($i -1)) $Lo_B = $iMin_B ContinueLoop 2 EndIf Next $iMin_B = $Lo_B ; minimum increment is one WEnd EndIf WEnd EndFunc ;==> ParallelExponetialSearch I hope this will be useful to someone. I believe it deserved a thread of its own!
    • cheeroke
      By cheeroke
      Hi all,
      I got this code and would like to be able to change Baud Rate and instead of sending character by character i would like to be able (if possible) to send whole string. But i don't know how to change it.
      I am taking input from file and processing whole line (this is done in FilesHandling.au3).
      To execute this i am just calling SendData("FileName", int) in "main" script.
      Any help very appreciated.
      #include <WinAPI.au3> #include <Array.au3> #include "FilesHandling.au3" ;init DLL function, we need handle to call the function $h = DllCall("Kernel32.dll", "hwnd", "CreateFile", "str", "\\.\COM19", "int", BitOR($GENERIC_READ,$GENERIC_WRITE), "int", 0, "ptr", 0, "int", $OPEN_EXISTING, "int", $FILE_ATTRIBUTE_NORMAL, "int", 0) $handle=$h[0] Func SendData($FileName, $LineNumber) ;string to be send $c = readFile($FileName, $LineNumber) $cLenght = StringLen($c) $aArray = StringSplit($c, "") ;_ArrayDisplay($aArray, "", Default, 64) For $i = 1 To $cLenght writeChar($handle, $aArray[$i], $cLenght) Next ;move to next line writeChar($handle, @CR,1) EndFunc ;write a single char func writeChar($handle,$c,) $stString = DLLStructCreate("char str") $lpNumberOfBytesWritten = 0 DllStructSetData($stString, 1, $c) $res = _WinAPI_WriteFile($handle, DllStructGetPtr($stString, "str"), 1,$lpNumberOfBytesWritten) if ($res<>true) then ConsoleWrite ( _WinAPI_GetLastErrorMessage() & @LF) EndIf EndFunc  
    • RC86
      By RC86
      Afternoon!
      I have a requirement to return both a string and an array from a function so as a result I put them both into an array and returned that.  I can access them in their entirety after returning them but then I can't seem to access the array elements after this.  Should I be able to or is there a prettier way?
      #include <Array.au3> ;Memory info returned as a string and an array $memoryInfo = _getMemoryInfo() msgbox(0,"Memory Info",$memoryInfo[0]) _ArrayDisplay($memoryInfo[1],"Memory as an Array") Local $newArray[7] $memoryInfo[1] = $newArray msgbox(0,"Test element",$newArray[0]) _ArrayDisplay($newArray) Func _getMemoryInfo() Local $newArray[7] Local $array = MemGetStats() $newArray[0] = $array[0] ;% of memory in use $newArray[1] = Round($array[1]/1024 * 0.001,2) ;Total physical RAM $newArray[2] = Round($array[2]/1024 * 0.001,2) ;Availaible physical RAM $newArray[3] = Round($array[3]/1024 * 0.001,2) ;Total pagefile $newArray[4] = Round($array[4]/1024 * 0.001,2) ;Available pagefile $newArray[5] = Round($array[5]/1024 * 0.001,2) ;Total virtual $newArray[6] = Round($array[6]/1024 * 0.001,2) ;Available virtual $memoryUsage = $newArray[1] - $newarray[2] $pagefileUsage = $newArray[3] - $newarray[4] ;Output/Return Local $returnArray[2] $returnArray[0] = "Memory: " & $memoryUsage & " GB/" & $newArray[1] & " GB " & @CRLF & "Pagefile: " & $pagefileUsage & " GB/" & $newArray[3] & " GB " $returnArray[1] = $newArray return $returnArray EndFunc A bit messy but hopefully it's understandable what I'm trying to achieve.
      Thanks!