Jump to content

Array fail, not loading data everytime.


TagK
 Share

Recommended Posts

I have another thread in regards to an anime information tool,

But it would not call attention to this issue, seeing as it has limited scope of interest.

This is the full code. The issue I am having at the moment is

Anime main.au3 (84) : ==> Subscript used with non-Array variable.:
$complete = $annURL & $regex[0] & $episodes
$complete = $annURL & $regex^ ERROR
->18:43:03 AutoIT3.exe ended.rc:1

The weird thing is, sometimes it works. Sometimes it does not. And I cannot figure it out. Any help would be most appriciated. I will even add your handle on the forums in the credits of the app when its done, as this has baffled me for a while.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <IE.au3>
#include <Inet.au3>
#include <array.au3>
#include <file.au3>

#region Interface
$MainForm = GUICreate("Anime info gatherer!", 532, 164, 192, 124)
$nameInputTxt = GUICtrlCreateInput("Type Name Here", 24, 16, 377, 21)
$getDataBtn = GUICtrlCreateButton("Fetch data", 24, 48, 75, 25)
$statusLabel = GUICtrlCreateLabel("Data fetching progress: Completed / Progress / Writing to CSV", 106, 53, 299, 24)
$SaveFileBox = GUICtrlCreateInput("", 32, 80, 90, 21)
$SavefileLabel = GUICtrlCreateLabel("Type the name of the file for temporary storage, testing only, .txt is added automatically", 125, 80, 249, 36)
$Radio1 = GUICtrlCreateRadio("Anime Show", 416, 16, 113, 17); to be used later
GUICtrlSetState($Radio1,True) ; setting anime as default
$Radio2 = GUICtrlCreateRadio("Manga", 416, 32, 113, 17); to be used later
$tableParse = GUICtrlCreateButton("Table thing", 32, 112, 75, 25)
GUISetState(@SW_SHOW)
$oIE = _IECreateEmbedded() ;making an embedded ie window
GUICtrlCreateObj($oIE,500,500,0,0) ; moving said window out of the way
#endregion Interface

#region variables

Global $SearchURL = "www.google.com/search?q=site:animenewsnetwork.com/encyclopedia/+"

#endregion

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $getDataBtn
_findAnime() ; runs the anime finder function - somehow its fucked now...
;ConsoleWrite($resultData)
Case $tableParse
_episodes()
EndSwitch
WEnd


Func _episodes()
local $dataz
local $filename = "dataz.txt"
local $resultData
Local $complete ; temporary to test, will eventually add global to it
$complete = "www.animenewsnetwork.com/encyclopedia/anime.php?id=1139&page=25"
$resultData = _IENavigate($oIE,$complete)
$resultData = _IEBodyReadHTML($oIE)
FileOpen("tableS.txt",2)
FileWrite("tableS.txt", $resultData)
FileClose("tableS.txt")
FileOpen($filename,1)
$dataz = StringRegExp($resultData,'
\w+.+', 2)
_FileWriteFromArray($filename,$dataz)
FileClose($filename)
GUICtrlSetData($SaveFileBox,"Done...")
EndFunc


Func _findAnime() ;function for locating the anime
local $urlread
Local $resultData
local $latency = "5000" ; if needed, will add option to ask for it later
$readData = GUICtrlRead($nameInputTxt) ; read the name of the show, user input required
$searchVar = $searchURL & $readData ; combine name of show and search string to produce a valid URL
ConsoleWrite($searchVar)
_IENavigate($oIE,$searchVar)
Sleep($latency)
_IEPropertyGet($oIE,"outerhtml")
$urlread = BinaryToString($resultData, 4) ; convert to usable data
Dim $regex[1]
$regex = StringRegExp($urlread, 'id=\d{1,6}', 2) ; extracting the ID of the anime from the data collected, it assumes first hit is correct.
_ArrayDisplay($regex)
;Sleep($latency)
$annURL = "http://www.animenewsnetwork.com/encyclopedia/anime.php?" ; just the default url for everything
$episodes = "&page=25" ; this one seems to be the default for all episode listings, for every show
$complete = $annURL & $regex[0] & $episodes ; combine the results of regex and everything
ConsoleWrite($complete)
_IENavigate($oIE,$complete)
Sleep($latency)
$getTables = _INetGetSource($complete)
FileOpen("kilde.txt",2)
FileWrite("kilde.txt",$getTables)
FileClose("kilde.txt")
ConsoleWrite("done")
EndFunc ;==>_findAnime

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

Link to comment
Share on other sites

Hi,

That's because your RegExp func does not always found matches, check for its @error macro or check if it's an array.

$regex = StringRegExp($urlread, 'id=d{1,6}', 2)
If @error = 0 Then ;matches
...

;or
$regex = StringRegExp($urlread, 'id=d{1,6}', 2)
If IsArray($regex) Then ;matches

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

I figured it out now, the problem was not with the array or the regex....

I had simply forgotten to add a variable to get the property i needed to parse the REGEX: >.<

$resultData = _IEPropertyGet($oIE,"outerhtml")
$urlread = BinaryToString($resultData, 4) ; convert to usable data
Dim $regex[1]
$regex = StringRegExp($urlread, 'id=d{1,6}', 2)

God I feel dumb now, this has been bothering me for almost 2 weeks now.

Thanks for the tip though mr FireFox.

Programming Novice, interested in c++ (i know maybe 1%) AutoIT and many more.Projects : Anime renamer

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...