Jump to content

Subscript used in non-accessible variable Error!


andrewz
 Share

Go to solution Solved by somdcomputerguy,

Recommended Posts

Marked my old thread as solved as the initial question is already solved. Now I got a new error :/

Sooo let's get to my question: I made a program which imports Data from a website called "www.immobilienscout24.de" with a little help from someone on stackoverflow and now it's finally working. BUT the problem is, it only works when the data is available, so if the owner of a property decides not to give the exact adress, it will print an error and stop working. That's the code:

If FileExists("Immobilien.csv") =false Then
FileWrite("Immobilien.csv","Name;Adresse;Tel;Objekt;Ort;Baujahr;Zi;frei/vermie.;Wfl./ qm;Kaltmiete;Warmmietpreis;Scout- ID"& @CRLF)
EndIf

#include <Inet.au3>
#include <Array.au3>
#include <String.au3>
Global $mobil_A= "0"
Global $telefon_A = "0"
Global $url = InputBox("ScoutID","Enter the Scout-ID")
Global $content = _INetGetSource($url)
Global $name_A = _StringBetween($content, '<span data-qa="contactName" class="font-bold">', '</span>')
Global $preis_A = _StringBetween($content, ' "offerPrice": "', '",')
Global $strase_A = _StringBetween($content, '<strong class="font-standard">' , '</strong><br/>')
Global $telefon_A = _StringBetween($content, '<div class="is24-phone-number hide">' ,'</div>')
Global $objekttyp_A = _StringBetween($content, '<dd class="is24qa-wohnungstyp">' ,'</dd>')
Global $ort_A = _StringBetween($content, '</strong><br/>' , '<br/>')
Global $baujahr_A = _StringBetween($content, '<dd class="is24qa-baujahr">','</dd>')
Global $zimmer_A = _StringBetween($content, '<dd class="is24qa-zimmer">','</dd>')
Global $bezugsfrei_A = _StringBetween($content, '<dd class="is24qa-bezugsfrei-ab">' ,'</dd>')
Global $wohnflache_A = _StringBetween($content, '<dd class="is24qa-wohnflaeche-ca">' ,'</dd>')
Global $preiswarm_A =_StringBetween($content, '<strong class="is24qa-gesamtmiete">','</strong>')




$aio= $name_A[0]&";"&$strase_A[0]&";"&$telefon_A[0]&";"&$objekttyp_A[0]&";"&$ort_A[0]&";"&$baujahr_A[0]&";"&$zimmer_A[0]&";"&$bezugsfrei_A[0]&";"&$wohnflache_A[0]&";"&$preis_A[0]&",00"&";"&$preiswarm_A[0]&";"&$url

$sString1 = StringReplace($aio, " ", "")
$sString2 = StringReplace($sString1, "<p>", "")
$sString3 = StringReplace($sString2, "<span>Mobil:</span>", "")
$sString4 = StringReplace($sString3, "</p>", "")
$sString5 = StringReplace($sString4, "Â", "")
$sString6 = StringReplace($sString5, '<spanclass="is24-operator">=</span>', "")
$sString7 = StringReplace($sString6, "EUR", "")
$sString8 = StringReplace($sString7, "<span>Telefon:</span>","")
$sStringfinal = StringReplace($sString8, @CRLF, "")


FileWrite ( "Immobilien.csv", $sStringfinal & @CRLF )

So here we got 2 example properties:

http://www.immobilienscout24.de/expose/78295011

http://www.immobilienscout24.de/expose/78294144

The first one DOESNT work at all. It just doesnt write anything down cuz there is no adress given.

For the second one it writes everything down perfectly fine cuz it is given as "Viktor-Scheffel-Str. 13".

Finally my question: Does anyone know how to make the program skip not existing values or bypass the error ? I would be soooo thankful if someone could help me!

Best regards, Andrew

 

EDIT: Adding the error code:

"C:\Users\assistent02\Desktop\ExportALPHA.au3" (27) : ==> Subscript used on non-accessible variable.:
$aio= $name_A[0]&";"&$strase_A[0]&";"&$telefon_A[0]&";"&$objekttyp_A[0]&";"&$ort_A[0]&";"&$baujahr_A[0]&";"&$zimmer_A[0]&";"&$bezugsfrei_A[0]&";"&$wohnflache_A[0]&";"&$preis_A[0]&",00"&";"&$preiswarm_A[0]&";"&$url
$aio= $name_A[0]&";"&$strase_A^ ERROR
->14:43:22 AutoIt3.exe ended.rc:1
+>14:43:22 AutoIt3Wrapper Finished.
>Exit code: 1 Time: 2.667
Edited by andrewz
Link to comment
Share on other sites

  • Solution

This bit of code may help. In it I use the _IsArray funtion. I do exit the script if the If is true, but you can do anything else that you want..

$Link = _StringBetween(ClipGet(), 'u=', '')

If NOT IsArray($Link) Then
MsgBox(48 + 4096, '', 'No User Link!')
Exit
EndIf
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

$Link = _StringBetween(ClipGet(), 'u=', '')

If NOT IsArray($Link) Then
MsgBox(48 + 4096, '', 'No User Link!')
Exit
EndIf

 

FINALLY! Dunno how much I could thank you now !!  :P

That's how it looks now if anyone is interested, I'm just gonna implent that into the original script.

EDIT: Optimized it so it's easier to understand.

#include <Inet.au3>
#include <Array.au3>
#include <String.au3>

Global $url = InputBox("ScoutID","Enter the Scout-ID")
Global $content = _INetGetSource($url)
Global $strase_A = _StringBetween($content, '<strong class="font-standard">' , '</strong><br/>')



If  IsArray($strase_A) Then
MsgBox(0,"INCLUDING","IT'S GIVEN")
$strase_B = $strase_A[0]
Else
MsgBox(0,"NOT INCLUDING","Not given...")
$strase_B = "/"
EndIf

MsgBox(0,"",$strase_B)
Edited by andrewz
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...