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                                How to post scriptsource        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                                How to post scriptsource        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

    • Ascer
      By Ascer
      1. Description.
      Udf working with MSDN System.Collections.ArrayList. Allow you to make fast operations on huge arrays, speed is even x10 better than basic _ArrayAdd.  Not prefered for small arrays < 600 items. 2. Requirements
      .NET Framework 1.1 - 4.5 (on this version Microsoft destroy old rules) System Windows 3. Possibilities.
      ;=============================================================================================================== ; UDF Name: List.au3 ; ; Date: 2018-02-17, 10:52 ; Description: Simple udf to create System Collections as ArrayList and make multiple actions on them. ; ; Function(s): _ListCreate -> Creates a new list ; _ListCapacity -> Gets a list size in bytes ; _ListCount -> Gets items count in list ; _ListIsFixedSize -> Get bool if list if fixed size ; _ListIsReadOnly -> Get bool if list is read only ; _ListIsSynchronized -> Get bool if list is synchronized ; _ListGetItem -> Get item on index ; _ListSetItem -> Set item on index ; ; _ListAdd -> Add item at end of list ; _ListClear -> Remove all list items ; _ListClone -> Duplicate list in new var ; _ListContains -> Get bool if item is in list ; _ListGetHashCode -> Get hash code for list ; _ListGetRange -> Get list with items between indexs ; _ListIndexOf -> Get index of item ; _ListInsert -> Insert a new item on index ; _ListInsertRange -> Insert list into list on index ; _ListLastIndexOf -> Get index last of item ; _ListRemove -> Remove first found item ; _ListRemoveAt -> Remove item in index ; _ListRemoveRange -> Remove items between indexs ; _ListReverse -> Reverse all items in list ; _ListSetRange -> Set new value for items in range ; _ListSort -> Sort items in list (speed of reading) ; _ListToString -> Get list object name ; _ListTrimToSize -> Remove unused space in list ; ; Author(s): Ascer ;=============================================================================================================== 4. Downloads
      List.au3 5. Examples
      SpeedTest _ArrayAdd vs ListAdd SpeedTest ArraySearch vs ListIndexOf Basic usage - crating guild with members  
    • ronmage
      By ronmage
      So I have a loop that keeps reading data from an array and searching it for the same value. If the value is no there it does work then adds the value to the array to prevent it from doing the same work.
      If _ArraySearch($ID,$filearray[$i]) = -1 Then Work.... _ArrayAdd($ID,$filearray[$i]) EndIf This is in a for loop hence $i
      So what is happening is the code works great for several hours. After a period of time _ArraySearch($ID,$filearray[$i]) will result in -1 even if $ID = $filearray. So it ready as if there is no data in the array. Anyone have this problem? 
       
      Also I am just running in using F5 not compiling it and running it if that makes a difference.
       
    • Robdog1955
      By Robdog1955
      I'm trying to click a button on a web page. I have added a couple of MsgBox lines to allow me to watch what happens on the page. As you can see the first half of my script enters data into text boxes on the page. I have no problem there. I just cannot click on the region buttons. The "set focus" line causes an outline to appear around the EU button and the "click button" line causes the "Pick a Region" text to disappear. Here is the code I have so far.
      #include <IE.au3> Local $oIE = _IECreate("http://questchecker.com/") Local $iQuestID = "123456" Local $sCharacterName = "CharacterName" Local $colForms = _IEFormGetCollection($oIE) $iCount = 0 For $oForm In $colForms $oFormElements = _IEFormElementGetCollection($oForm) For $oFormElement In $oFormElements $iCount = $iCount + 1 Local $sTagName = StringLower($oFormElement.tagName) Local $sElementType = $oFormElement.type Local $sElementName = $oFormElement.name Switch $iCount Case 6 _IEFormElementSetValue($oFormElement, "MyRealm", 0) ; realm Case 7 _IEFormElementSetValue($oFormElement, $sCharacterName, 0) Case 8 _IEFormElementSetValue($oFormElement, $iQuestID, 0) EndSwitch Next Next Local $oButtons = _IEGetObjByName($oIE, "questForm") For $oButton In $oButtons If _IEFormElementGetValue($oButton) = "US" Then MsgBox(0, "", "Click Okay to set focus") _IEAction($oButton, "focus") MsgBox(0, "", "Click Okay to click button") _IEAction($oButton, "click") ExitLoop EndIf Next MsgBox(0, "", "Click Okay to quit") _IEQuit($oIE) Exit  
    • Dent
      By Dent
      As the title says. I open IE11 and navigate to a page with the following HTML5 file upload container in Capture0.JPG
      I want to click Add Files but I haven't been able to. Here's the code that handles the Add Files button in Capture.JPG
      _IEGetObjectById and then using _IEAction to click it doesn't work. I can't give access to the actual page unfortunately because it's password protected.
      All suggestions welcome.


    • FMS
      By FMS
      Hello,
      I'm trying to read a binary file to an array but couln't get it to work.
      Also I coul not find any help in the forum around this subject whish was helpfull.
      Is there any way it could be done?
      I tried a lot of ways but maybe somebody know's the right way?
      #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <File.au3> #include <Array.au3> #include <AutoItConstants.au3> Local $in=FileOpen("TEST_labels.idx1-ubyte",16) ; 16+0=Read binary Local $data = FileRead($in) Local $FileArray = BinaryToString($data,4) ;~ $FileArray = StringSplit($BinarydData, @CRLF, 1+2) ;~ Local $FileArray = StringRegExp($BinarydData, "[^\r\n]+", 3) FileClose($in) _ArrayDisplay($FileArray,"$FileArray","",32) MsgBox($MB_SYSTEMMODAL, "", "$FileArray = " & $FileArray )  
      TEST_labels.idx1-ubyte