Jump to content

Open webpages by checking boxes


Recommended Posts

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 :)

Link to comment
Share on other sites

  • Developers

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 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

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

  • Developers
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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

Link to comment
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 :)

Link to comment
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).

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

×
×
  • Create New...