Jump to content

Reading line on a website without browser opened


Recommended Posts

Hello guys, I'm new on autoit but i can do scripts without help in some areas like pixel search, send keys in windows even if they are minimised and stuff, but I'm having trouble in this one. What i was trying to make is a script that can read a word from a website without the browser being opened, because i found a script made by someone that would check a certain version of a program from a website that the program was posted to download it, so i wanted to "translate" it to only read the rank on Halo 3 from ANY gamertag and the Xbox Live status... I used koda to make the labels and i made a input box and a button, (so when you press the button, it checks the rank and status, and then you can change the gamertag again and click the button again).

**Like, many already know, but for those who don't, the Halo 3 name from a person is the same from the xbox live gamertag, as like the other xbox games are.

So, continuing. I wanted the script to read the rank and the xbox live status, so i used _INetGetSource from the websites that already contain the gamertags cuz of the inputbox, (the script would read the input box and put the gamertag in the link) and then i tryed to use StringRegExp to read a part of that source, but the problem it trys to read the source, it says that the _INetGetSource func is unknown.

I'm posting the whole code of the script so you guys can check it out and maybe help me:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$window = GUICreate("H3 Checker", 179, 123, -1, -1)
$status = GUICtrlCreateLabel("Online Status:", 8, 8, 70, 17)
$rank = GUICtrlCreateLabel("Highest Rank:", 8, 32, 72, 17)
$status1 = GUICtrlCreateLabel("", 88, 8, 4, 4)
$rank1 = GUICtrlCreateLabel("", 88, 32, 4, 4)
$gt = GUICtrlCreateInput("Input Gamertag", 8, 56, 161, 21)
$check = GUICtrlCreateButton("Check Status", 48, 88, 81, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $check
            check()
    EndSwitch
WEnd

Func check()
    $1 = GUICtrlRead($gt)
    $status_is = ConsoleWrite(_INetGetSource('http://live.xbox.com/en-US/profile/profile.aspx?pp=0&GamerTag='&$1))
    $status_this = StringRegExp($status_is, 'Current Status:<br /><span class="XbcLIVEText">(*?)<', 3)
    GUICtrlSetData($status1, $status_this[0])
    $rank_is = ConsoleWrite(_INetGetSource('http://www.bungie.net/Stats/Halo3/Default.aspx?player='&$1))
    $rank_this = StringRegExp($rank_is, 'Highest Skill: <span id="ctl00_mainContent_identityStrip_lblSkill">(*?)<', 3)
    GUICtrlSetData($rank1, $rank_this[0])
Endfunc

PS: I tryed to search but everything i found was related with the browser being on. Oh, and I still use everything that Koda putted in the code.

If you guys can help me, thank you. =)

-Stylez

Edited by Stylez
Link to comment
Share on other sites

Your ConsoleWrite() lines are affecting your variables $status_is and $rank_is

I don't think your RegEx are going to work either, the '(*?)' might be a problem...

_INETGetSource is getting the source of the wrong IE frame also, and that is causing the RegEx to return errors rather than arrays.

Edited by MrMitchell
Link to comment
Share on other sites

So what do i change? It's kinda the first time i work with StringRegExp and _INetGetSource =S

EDIT: Should i change ConsoleWrite to ConsoleRead? I really dunno much about this... I only started working on autoit a month ago... =S

Edited by Stylez
Link to comment
Share on other sites

For the ConsoleWrite, change from:

$status_is = ConsoleWrite(_INetGetSource('http://live.xbox.com/en-US/profile/profile.aspx?pp=0&GamerTag='&$1))

To:

$status_is = _INetGetSource('http://live.xbox.com/en-US/profile/profile.aspx?pp=0&GamerTag='&$1)
ConsoleWrite($status_is)
Link to comment
Share on other sites

Ah! I thought i could put console writhe after the staus_is and rank_is and then add the _inetgetsource after it. =)

But it still ain't working... I think that the &$1 is correct... Like, i made $1 = GUICtrlRead($gt) to read the input, then the website link will be completed withe the input text.

But when i try to press "Check" in the error, it appears:

(33) : ==> Subscript used with non-Array variable.:

GUICtrlSetData($status1, $status_this[0])

GUICtrlSetData($status1, $status_this^ ERROR

I dunno whats wrong =S

(Being from another country can be a problem here... I'm not english, i'm portuguese, but i can read and understand english really good, except when it comes to programming xD)

EDIT: I think i know whats wrong with the (*?) part... I guess that since for the status it is a full word, like Online, Offline, Away, etc, i think i have to use (?i[a-z]) and for the rank, since it is 2 digits max, (it goes from 1 to 50), i think i have to use [[:digit:]] right?

Edited by Stylez
Link to comment
Share on other sites

It's because $status_this is not an array, but you're using it as such.

Your StringRegExp() function is not returning an array, because it can't find your RegEx.

After the line ConsoleWrite($status_this), search the text that was output and see if you can find your RegEx "Current Status:<br /><span class="XbcLIVEText">(*?)<". Also, in this RegEx, you may want to change "(*?)" to something like "\w*", as I don't think "(*?)" will work or is even valid in this or any RegEx.

However, if you go into Internet Explorer and view source from there, you will find the "Current Status".

I have to leave now, so hopefully someone will jump on and help you out with it. That webpage you are working with has frames, AutoIt and IE are getting source from different frames. I've never had this problem so I don't know how to resolve it, but I am sure someone else out there does...

Edit: About the rank digits, you can simply use "\d{1,2}" or "\d\d" if you are looking for two digits.

Edited by MrMitchell
Link to comment
Share on other sites

Thanks for the help dude, i hope someone jumps in too. =)

EDIT: in the \w nd \d\d how do i put the? with out "( )" or without them? Like so:

This

StringRegExp($status_is, 'Current Status:<br /><span class="XbcLIVEText">\w', 3)

Or this:

StringRegExp($status_is, 'Current Status:<br /><span class="XbcLIVEText">(\w)', 3)
Edited by Stylez
Link to comment
Share on other sites

Sorry for the double post, but i really need help on this script... Sorry =S

EDIT: The code i got atm is this:

#include <INet.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$window = GUICreate("H3 Checker", 179, 123, -1, -1)
$status = GUICtrlCreateLabel("Online Status:", 8, 8, 70, 17)
$rank = GUICtrlCreateLabel("Highest Rank:", 8, 32, 72, 17)
$status1 = GUICtrlCreateLabel("", 88, 8, 4, 4)
$rank1 = GUICtrlCreateLabel("", 88, 32, 4, 4)
$gt = GUICtrlCreateInput("Input Gamertag", 8, 56, 161, 21)
$check = GUICtrlCreateButton("Check Status", 48, 88, 81, 25, $WS_GROUP)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $check
            check()
    EndSwitch
WEnd

Func check()
Local $1, $status_is, $status_this, $rank_is, $rank_this
    $1 = GuiCtrlRead($gt)
While 2
    $status_is = _INetGetSource('http://live.xbox.com/en-US/profile/profile.aspx?pp=0&GamerTag='&$1)
    ConsoleWrite($status_is)
    $status_this = StringRegExp('Current Status:<br /><span class="XbcLIVEText">(\w)', 'Current Status:<br /><span class="XbcLIVEText">(\w)', 1, $status_is)
    ConsoleWrite($status_this)
    GUICtrlSetData($status1, $status_this, "")
WEnd
While 3
    $rank_is = _INetGetSource('http://www.bungie.net/Stats/Halo3/Default.aspx?player='&$1)
    ConsoleWrite($rank_is)
    $rank_this = StringRegExp('Highest Skill: <span id="ctl00_mainContent_identityStrip_lblSkill">(\d\d)<', 1, $rank_is)
    ConsoleWrite($rank_this)
    GUICtrlSetData($rank1, $rank_this, "")
WEnd
Endfunc
Edited by Stylez
Link to comment
Share on other sites

The syntax changes when you use INetGet() instead of _INetGetSource(). If you just straight replace it you're going to get a 0 (fail) or 1 (success). I tried INetGet and I get the same results (HTML from the wrong frame).

Also, you might want to get rid of the While 2 and While 3 loops

Link to comment
Share on other sites

Here is another approach, I'm not with RegExpress..

; demonstration to find chracters that change between to standard points
; or just find a string
#include <IE.au3>
#include <String.au3>

;------------- User input --------------
$URL = "http://www.autoitscript.com/" ; web address
$Find = "Welcome to the " ; my info shows after this line... or just find this line
$Before = "- the home " ; my info shows before this line... or set as ""
; ------------ End User input -------------

$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
InetGet($URL, $sloc)
$sfile = FileOpen($sloc, 0)
$num = 0
While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = _StringBetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is *" & $Found[0] & "*    ", 5)
        ExitLoop
    EndIf
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

did you test the actual script I wrote first?

8)

The one you wrote worked so perfectly, but when i tryed to put the actual web link i want to find the string and the string between it and after it, it just gives me an error saying "Subscript used with non-Array variable" and i see it points to the 0 part after the $Found, so i remove it, and it works, but it's not finding what im looking for... For example, i was trying to find the number 35, but in the The string found was *...* it says 0 for some reason... I really dunno whats wrong... Let me post the code i have (The one you posted but edited) here:

; demonstration to find chracters that change between to standard points
; or just find a string
#include <IE.au3>
#include <String.au3>

;------------- User input --------------
$URL = "http://www.bungie.net/Stats/Halo3/Default.aspx?player=crazyprice"; web address
$Find = "Highest Skill: "; my info shows after this line... or just find this line
$Before = "  |  Total"; my info shows before this line... or set as ""
; ------------ End User input -------------

$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
InetGet($URL, $sloc)
$sfile = FileOpen($sloc, 0)
$num = 0
While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found   " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = _StringBetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is *" & $Found[0] & "*  ", 5)
        ExitLoop
    EndIf
WEnd
Edited by Stylez
Link to comment
Share on other sites

The initial code was based on the Autoit page which is "Text"

The following will show the real "coded" info on your page

; demonstration to find chracters that change between to standard points
; or just find a string
#include <IE.au3>
#include <String.au3>

;------------- User input --------------
$URL = "http://www.bungie.net/Stats/Halo3/Default.aspx?player=crazyprice"; web address
$Find = "Highest Skill: "; my info shows after this line... or just find this line
$Before = "|" ; my info shows before this line... or set as ""
; ------------ End User input -------------

$sloc = @TempDir & "\stest.txt"
FileDelete($sloc)
InetGet($URL, $sloc)
$sfile = FileOpen($sloc, 0)
$num = 0
While 2
    $num = $num + 1
    $sline = FileReadLine($sfile, $num)
    If @error Then
        MsgBox(262208, "Fail", "The string was NOT found   ")
        FileClose($sfile)
        Exit
    EndIf
    If StringInStr($sline, $Find) Then
        MsgBox(64, "Success", "The string " & $Find & " was found    " & @CRLF & " on line # " & $num, 5)
        If $Before = "" Then ExitLoop
        $Found = _StringBetween($sline, $Find, $Before)
        MsgBox(64, "Found", "The string is *" & $Found[0] & "*    ", 15)
        ExitLoop
    EndIf
WEnd

You can use stringbetween for the "code" in the msgbox to get the "35"

8)

NEWHeader1.png

Link to comment
Share on other sites

Nice one dude! I saw that the only thing that changed from my edit was the Before this line part, and it works! Now i can try to complete my script! Thanks dude! Ill post the full code when i finish ok? =)

PS: I'll try to put this on my GUI made script, so in case anything happens, ill post it here.

Thanks again dude! =D

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...