Jump to content
Sign in to follow this  
incepator

_ArrayUnique problem

Recommended Posts

incepator

hello to everyone

Who can me help with a script?

I would be grateful ...

Fail to make it to exclude duplicate lines ...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <String.au3>
#include <Array.au3>
#include <GuiListView.au3>
#NoTrayIcon
$Form1 = GUICreate("", 721, 650, -1, -1)
GUISetBkColor(0xB9D1EA)
$Button1 = GUICtrlCreateButton("Select List", 2, 2, 211, 25, $WS_BORDER)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetCursor (-1, 0)
$Label1 = GUICtrlCreateLabel("", 216, 8, 400, 17, $WS_BORDER)
$Input0 = GUICtrlCreateInput("1", 630, 4, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER,$WS_BORDER))
GUICtrlSetTip($Input0, "Insert line")
$Label2 = GUICtrlCreateLabel("Start Page:", 8, 30, 78, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("1", 75, 27, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER,$WS_BORDER))
$Label3 = GUICtrlCreateLabel("Stop Page:", 160, 30, 78, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("10", 225, 27, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER,$WS_BORDER))
$Label4 = GUICtrlCreateLabel("Total Link:", 310, 30, 125, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("", 375, 27, 241, 17, $WS_BORDER)
$Progress1 = GUICtrlCreateProgress(104, 53, 598, 12)
$Button2 = GUICtrlCreateButton("Start", 8, 47, 75, 22, $WS_BORDER)
GUICtrlSetFont(-1, 11, 800, 0, "Arial Narrow")
GUICtrlSetCursor (-1, 0)
$ListView1 = GUICtrlCreateListView("All Links", 4, 72, 713, 572)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 700)
GUICtrlSetCursor (-1, 2)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$adauga_fisier = FileOpenDialog("Select", @DesktopDir& "\", "Fisier Txt (*.txt)", 1)
If Not @error Then
     GUICtrlSetData($Label1,$adauga_fisier)
EndIf
Case $Button2
If GUICtrlRead($Label1) = "" Then
MsgBox(8240,"Warning","No File .txt !")
ElseIf GUICtrlRead($Input1) = "" Or GUICtrlRead($Input1) = 0 Then
MsgBox(8240,"Warning","No first page !")
ElseIf GUICtrlRead($Input2) = "" Or GUICtrlRead($Input2) = 0 Then
MsgBox(8240,"Warning","No page !")
ElseIf Not GUICtrlRead($Label1) = "" Then
$atentionare_start = MsgBox(8228,"Info","Please Wait...")
If $atentionare_start = 6 Then
     $linia_fisier = FileOpen(GUICtrlRead($Label1), 0)
     If Not @error Then
     $cuvant_linie = FileReadLine($linia_fisier,GUICtrlRead($Input0))
     FileClose($linia_fisier)
     EndIf
     For $de_la_pagina = GUICtrlRead($Input1) To GUICtrlRead($Input2)
     GUICtrlSetData($Input1,$de_la_pagina)
     $link_generat = "http://en.search.wordpress.com/?q="&$cuvant_linie&"&t=comment&s=date&page="&GUICtrlRead($Input1)
     $link =_IECreate($link_generat&"/",Default,0,1,0)
     _IELoadWait($link)
     Global $SourceText = _IEBodyReadHTML($link)
     _IEQuit($link)
     $string1 = _StringBetween($SourceText,'class=post-title href="','">')
     If IsArray($string1) Then
     $arry_unic = _ArrayUnique($string1)
     For $1 = 1 To UBound($arry_unic)-1
     GUICtrlSetData($Progress1,Random(80,100))
     GUICtrlCreateListViewItem($arry_unic[$1], $ListView1)
     GUICtrlSetData($Label5,$1*GUICtrlRead($Input1))
     Next
     EndIf
     Next
     MsgBox(8256,"Info","Finish")
     $salvare = FileSaveDialog("Save...",@DesktopDir,"Text files (*.txt)","",GUICtrlRead($Input2)&" Pages - "&"Nr. Links - "&GUICtrlRead($Label5)&".txt")
     If Not @error Then
     Local $deschide_salvare = FileOpen($salvare, 1)
     For $i = 0 To _GUICtrlListView_GetItemCount($ListView1)-1
     FileWrite($deschide_salvare,_GUICtrlListView_GetItemTextString($ListView1,$i)&@CRLF)
     Next
     EndIf
EndIf
EndIf
EndSwitch
WEnd

thanks !

_ArrayUnique not working... :(

list words.txt

Share this post


Link to post
Share on other sites
UEZ

Try this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <String.au3>
#include <Array.au3>
#include <GuiListView.au3>
#NoTrayIcon
$Form1 = GUICreate("", 721, 650, -1, -1)
GUISetBkColor(0xB9D1EA)
$Button1 = GUICtrlCreateButton("Select List", 2, 2, 211, 25, $WS_BORDER)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
GUICtrlSetCursor(-1, 0)
$Label1 = GUICtrlCreateLabel("", 216, 8, 400, 17, $WS_BORDER)
$Input0 = GUICtrlCreateInput("1", 630, 4, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER, $WS_BORDER))
GUICtrlSetTip($Input0, "Insert line")
$Label2 = GUICtrlCreateLabel("Start Page:", 8, 30, 78, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("1", 75, 27, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER, $WS_BORDER))
$Label3 = GUICtrlCreateLabel("Stop Page:", 160, 30, 78, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("10", 225, 27, 81, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_NUMBER, $WS_BORDER))
$Label4 = GUICtrlCreateLabel("Total Link:", 310, 30, 125, 17)
GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
$Label5 = GUICtrlCreateLabel("", 375, 27, 241, 17, $WS_BORDER)
$Progress1 = GUICtrlCreateProgress(104, 53, 598, 12)
$Button2 = GUICtrlCreateButton("Start", 8, 47, 75, 22, $WS_BORDER)
GUICtrlSetFont(-1, 11, 800, 0, "Arial Narrow")
GUICtrlSetCursor(-1, 0)
$ListView1 = GUICtrlCreateListView("All Links", 4, 72, 713, 572)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 700)
GUICtrlSetCursor(-1, 2)
GUISetState(@SW_SHOW)
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $adauga_fisier = FileOpenDialog("Select", @DesktopDir & "", "Fisier Txt (*.txt)", 1)
            If Not @error Then
                GUICtrlSetData($Label1, $adauga_fisier)
            EndIf
        Case $Button2
            If GUICtrlRead($Label1) = "" Then
                MsgBox(8240, "Warning", "No File .txt !")
            ElseIf GUICtrlRead($Input1) = "" Or GUICtrlRead($Input1) = 0 Then
                MsgBox(8240, "Warning", "No first page !")
            ElseIf GUICtrlRead($Input2) = "" Or GUICtrlRead($Input2) = 0 Then
                MsgBox(8240, "Warning", "No page !")
            ElseIf Not GUICtrlRead($Label1) = "" Then
                $atentionare_start = MsgBox(8228, "Info", "Please Wait...")
                If $atentionare_start = 6 Then
                    $linia_fisier = FileOpen(GUICtrlRead($Label1), 0)
                    If Not @error Then
                        $cuvant_linie = FileReadLine($linia_fisier, GUICtrlRead($Input0))
                        FileClose($linia_fisier)
                    EndIf
                    Dim $master_array[1]
                    For $de_la_pagina = GUICtrlRead($Input1) To GUICtrlRead($Input2)
                        GUICtrlSetData($Input1, $de_la_pagina)
                        $link_generat = "http://en.search.wordpress.com/?q=" & $cuvant_linie & "&t=comment&s=date&page=" & GUICtrlRead($Input1)
                        $link = _IECreate($link_generat & "/", Default, 0, 1, 0)
                        _IELoadWait($link)
                        Global $SourceText = _IEBodyReadHTML($link)
                        _IEQuit($link)
                        $string1 = _StringBetween($SourceText, 'class="post-title" href="', '">')
                        If IsArray($string1) Then
                            _ArrayConcatenate($master_array, $string1, 1)
                        EndIf
                    Next
                    _ArrayDelete($master_array, 0)
                    $arry_unic = _ArrayUnique($master_array)
                    For $1 = 1 To UBound($arry_unic) - 1
                        GUICtrlSetData($Progress1, Random(80, 100))
                        GUICtrlCreateListViewItem($arry_unic[$1], $ListView1)
                        GUICtrlSetData($Label5, $1 * GUICtrlRead($Input1))
                    Next
                    MsgBox(8256, "Info", "Finish")
                    $salvare = FileSaveDialog("Save...", @DesktopDir, "Text files (*.txt)", "", GUICtrlRead($Input2) & " Pages - " & "Nr. Links - " & GUICtrlRead($Label5) & ".txt")
                    If Not @error Then
                        Local $deschide_salvare = FileOpen($salvare, 1)
                        For $i = 0 To _GUICtrlListView_GetItemCount($ListView1) - 1
                            FileWrite($deschide_salvare, _GUICtrlListView_GetItemTextString($ListView1, $i) & @CRLF)
                        Next
                    EndIf
                EndIf
            EndIf
    EndSwitch
WEnd

You made a mistake in the _StringBetween() line and the logic to make it unique was false. ;)

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
incepator

Hello!

I have a problem ...

How can number the number of rows in "ListViewItem"?

and how to reduce duplicate rows?

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <IE.au3>
#include <String.au3>
#include <Array.au3>
#include <GuiListView.au3>
$Form1 = GUICreate("", 585, 442, 192, 124)
$Label1 = GUICtrlCreateLabel("Start Line Nr. Word", 8, 16, 95, 17)
$Input1 = GUICtrlCreateInput("1", 104, 16, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
$Label2 = GUICtrlCreateLabel("Stop To Line Nr. Word", 160, 16, 111, 17)
$Input2 = GUICtrlCreateInput("4", 285, 16, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
$Label3 = GUICtrlCreateLabel("Start Page Nr.", 336, 16, 71, 17)
$Input3 = GUICtrlCreateInput("1", 405, 16, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
$Label4 = GUICtrlCreateLabel("Start Page Nr.", 461, 16, 71, 17)
$Input4 = GUICtrlCreateInput("2", 530, 16, 49, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER,$ES_NUMBER))
$ListView1 = GUICtrlCreateListView("Total Link Nr|Links", 2, 64, 578, 374)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 80)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 400)
$Button1 = GUICtrlCreateButton("Extract", 8, 36, 75, 22)
GUISetState(@SW_SHOW)
$list_words = "Words.txt"
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button1
$first_word = GUICtrlRead($Input1)
$last_word = GUICtrlRead($Input2)
  Dim $master_array[1]
  $open_read = FileOpen($list_words,0)
For $page = GUICtrlRead($Input3) To GUICtrlRead($Input4)
For $word = $first_word To $last_word
  $actual_word = FileReadLine($open_read,$word)
  $Link_Generate = _IECreate("http://en.search.wordpress.com/?q=" & $actual_word & "&t=comment&page=" & $page , 0, 0, 1, 0)
  _IELoadWait($Link_Generate)
  $text_extract = _IEBodyReadHTML($Link_Generate)
  _IEQuit($Link_Generate)
  $pages = _StringBetween($text_extract, 'class=post-title href="','">')
  If IsArray($pages) Then
   _ArrayConcatenate($master_array, $pages, 1)
  EndIf
Next
  _ArrayDelete($master_array, 0)
  $arry_unic = _ArrayUnique($master_array)
  For $1 = 1 To UBound($arry_unic) - 1
   $prima_culoare = GUICtrlCreateListViewItem("|"&$arry_unic[$1], $ListView1)
  Next
Next
  MsgBox(64,"Info","Finish !")
$salvare_totala = FileSaveDialog("Save...",@DesktopDir,"Text files (*.txt)","",GUICtrlRead($Input1))
   If Not @error Then
     Local $saves = FileOpen($salvare_totala&".txt", 1)
     For $i = 0 To _GUICtrlListView_GetItemCount($ListView1)-1
     FileWrite($saves,_GUICtrlListView_GetItemTextString($ListView1,$i)&@CRLF)
     Next
   EndIf

EndSwitch
WEnd

Words.txt

Edited by incepator

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
Sign in to follow this  

×