BASIC

Author Topic: Need help reading a web value  (Read 3203 times)

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Need help reading a web value
« on: 2012-Sep-13 »
Hi! I need a bit help, if this can be done.

If you are used to Magic TG, you got a DCI ID. With this ID you can earn points playing Magic. To see your DCI points you enter at

http://www.wizards.com/Magic/PlaneswalkerPoints/

And enter your dci id

So the page http://www.wizards.com/Magic/PlaneswalkerPoints/2300205446 shows the points of player 2300205446. This info is not private but public.

I need a function

Score=get_dci(dci_id)

Where score is the seasonal score in this previous page. Anyone?
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline msx

  • Prof. Inline
  • *****
  • Posts: 773
    • View Profile
Re: Need help reading a web value
« Reply #1 on: 2012-Sep-13 »
No se puede, ya que el navegador hace una petición por ajax al servidor una vez cargada la página, y eso no lo hace si lo leemos con NETWEBGET$.

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10719
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Need help reading a web value
« Reply #2 on: 2012-Sep-13 »
Pay attention. It presents me a German page. So see if you can force the english output.
Netwebget$ should work fine.

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: Need help reading a web value
« Reply #3 on: 2012-Sep-14 »
It read your local language. On the bottom right you can change language.
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1781
    • View Profile
    • Homepage
Re: Need help reading a web value
« Reply #4 on: 2012-Sep-14 »
Looks to me like you have to query this location (using NETWEBGET$ ofcourse):

http://www.wizards.com/Magic/PlaneswalkerPoints/JavaScript/GetPointsSummary/2300205446

You get some JSON encoded stuff back that is easy to parse out the number from:
Code: GLBasic [Select]
{"Result":true,"SessionExpired":false,"Data":[{"Key":"LifetimePoints","Value":29,"ReplaceElement":false},
{"Key":"Level","Value":6,"ReplaceElement":false},{"Key":"CurrentLevel","Value":6,"ReplaceElement":false},
{"Key":"NextLevel","Value":7,"ReplaceElement":false},{"Key":"PointsToNextLevel","Value":"1 points
away"
,"ReplaceElement":false},{"Key":"Percentage","Value":0.8,"ReplaceElement":false},
{"Key":"Avatar","Value":"\u003cimg src=\"\" alt=\"\" /\u003e","ReplaceElement":false},
{"Key":"NamePlate","Value":"\u003cimg src=\"http://media.wizards.com/ContentResources/Magic/
PlaneswalkerPoints/LevelNames_4_en_US.png\" alt=\"\" /\u003e"
,"ReplaceElement":false},{"Key":"Point","Value":"\r
\n    \u003cdiv class=\"HistoryPanelRow

Make sure you use NETWEBGET$ (with the $ at the end), not NETWEBGET(). The NETWEBGET$ downloads and save data in a string instead of saving in a file on your harddrive.
« Last Edit: 2012-Sep-14 by Moru »

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: Need help reading a web value
« Reply #5 on: 2012-Sep-15 »
Moru, thanks for your response, but this url returns an error on firefox, and in NETWEBGET$ I get this:

Code: GLBasic [Select]
<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="/Magic/PlaneswalkerPoints/Error">here</a>.</h2>
</body></html>

as I dont know how you get thi url, I dont know if it has changed...

I am using

Code: GLBasic [Select]
a$=NETWEBGET$("www.wizards.com","/Magic/PlaneswalkerPoints/JavaScript/GetPointsSummary/2300205446",80,52048,5000)
 
« Last Edit: 2012-Sep-15 by ampos »
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1781
    • View Profile
    • Homepage
Re: Need help reading a web value
« Reply #6 on: 2012-Sep-16 »
Seems it is a POST request but with no data posted. Try Gernots tutorial for POST queries:
http://www.glbasic.com/forum/index.php?topic=2866.msg20989#msg20989

Offline ampos

  • Prof. Inline
  • *****
  • Posts: 1594
    • View Profile
    • AMpostata Website
Re: Need help reading a web value
« Reply #7 on: 2012-Sep-19 »
Im sorry, but I can not understand Gernot post about POST queries.

How did you get the JSON text?

Code: GLBasic [Select]
{"Result":true,"SessionExpired":false,"Data":[{"Key":"LifetimePoints","Value":29,"ReplaceElement":false},
{"Key":"Level","Value":6,"ReplaceElement":false},{"Key":"CurrentLevel","Value":6,"ReplaceElement":false},
{"Key":"NextLevel","Value":7,"ReplaceElement":false},{"Key":"PointsToNextLevel","Value":"1&nbsp;points
away"
,"ReplaceElement":false},{"Key":"Percentage","Value":0.8,"ReplaceElement":false},
{"Key":"Avatar","Value":"\u003cimg src=\"\" alt=\"\" /\u003e","ReplaceElement":false},
{"Key":"NamePlate","Value":"\u003cimg src=\"http://media.wizards.com/ContentResources/Magic/
PlaneswalkerPoints/LevelNames_4_en_US.png\" alt=\"\" /\u003e"
,"ReplaceElement":false},{"Key":"Point","Value":"\r
\n    \u003cdiv class=\"HistoryPanelRow

I would love a program that gives me this JSON file/text
check my web and/or my blog :D
http://diniplay.blogspot.com (devblog)
http://www.ampostata.org
http://ampostata.blogspot.com
I own PC-Win, MacBook 13", iPhone 3G/3GS/4G and iPAC-WinCE

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1781
    • View Profile
    • Homepage
Re: Need help reading a web value
« Reply #8 on: 2012-Sep-19 »
Just about any web-browser can do this for you. Some needs plugins, others work straight off. Opera has it built-in.

MrTAToad

  • Guest
Re: Need help reading a web value
« Reply #9 on: 2012-Sep-19 »
Wasn't there a routine somewhere in the forums that could read a JSON file ?

Offline Moru

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 1781
    • View Profile
    • Homepage
Re: Need help reading a web value
« Reply #10 on: 2012-Sep-19 »
The problem here is to download the json in the first place. You need to do a post request, not a get.