Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #45824

Re: Accessing Json data (I think I am nearly there) complete beginner

Path csiph.com!usenet.pasdenom.info!gegeweb.org!newsfeed.kamp.net!newsfeed.kamp.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'parameters': 0.04; 'json': 0.07; '#print': 0.09; 'stating': 0.09; 'def': 0.12; '"w")': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'subject:Accessing': 0.16; 'subject:beginner': 0.16; 'urllib': 0.16; 'wrote:': 0.18; 'hey': 0.18; 'trying': 0.19; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'guys': 0.24; "i've": 0.25; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'subject:) ': 0.29; 'andrew': 0.30; 'code': 0.31; 'directly,': 0.31; 'prints': 0.31; 'week.': 0.33; 'checking': 0.33; 'skip:b 30': 0.33; 'subject: (': 0.35; 'skip:u 20': 0.35; 'something': 0.35; 'received:84': 0.35; 'really': 0.36; 'skip:j 20': 0.36; 'subject:data': 0.36; 'method': 0.36; 'thanks': 0.36; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'guy': 0.60; 'browser': 0.61; 'simply': 0.61; "you've": 0.63; 'different': 0.65; 'worth': 0.66; 'url:co': 0.67; 'header:Reply-To:1': 0.67; 'anything.': 0.68; 'subject:there': 0.68; 'below:': 0.68; 'reply-to:no real name:2**0': 0.71; 'reply-to:addr:python.org': 0.84; 'subject:think': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=LparlBtc c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=oyR3mlnJdzkA:10 a=WNIOzSasJIgA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=vU_qchQ8ZRcA:10 a=BxLX_y_qAAAA:8 a=E_aenHZuMMDNRfWvDFwA:9 a=pn1K1XzjC69SEQMy:21 a=Uv9ofEXF_7qUo9pf:21 a=wPNLvfGTeEIA:10
X-AUTH mrabarnett:2500
Date Thu, 23 May 2013 17:53:23 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130509 Thunderbird/17.0.6
MIME-Version 1.0
To python-list@python.org
Subject Re: Accessing Json data (I think I am nearly there) complete beginner
References <509030d9-08fd-40b2-8a89-cd4ecfad7a1a@googlegroups.com>
In-Reply-To <509030d9-08fd-40b2-8a89-cd4ecfad7a1a@googlegroups.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2023.1369328186.3114.python-list@python.org> (permalink)
Lines 65
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1369328186 news.xs4all.nl 15914 [2001:888:2000:d::a6]:32987
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45824

Show key headers only | View raw


On 23/05/2013 17:09, Andrew Edwards-Adams wrote:
> Hey guys
> I think its worth stating that I have been trying to code for 1 week.
> I am trying to access some Json data. My innitial code was the below:
>
> "import mechanize
> import urllib
> import re
>
> def getData():
>      post_url = "http://www.tweetnaps.co.uk/leaderboards/leaderboard_json/all_time"
>      browser = mechanize.Browser()
>      browser.set_handle_robots(False)
>      browser.addheaders = [('User-agent', 'Firefox')]
>
>      #These are the parameters you've got from checking with the aforementioned tools
>      parameters = {'page' : '1',
>                    'rp' : '10',
>                    'sortname' : 'total_pl',
>                    'sortorder' : 'desc'}
>      #Encode the parameters
>      data = urllib.urlencode(parameters)
>      trans_array = browser.open(post_url,data).read().decode('UTF-8')
>
>      #print trans_array
>
>      myfile = open("test.txt", "w")
>      myfile.write(trans_array)
>      myfile.close()
>
> getData()
>
> raw_input("Complete")"
>
> I was recommended to use the following code to access the Json data directly, however I cannot get it to return anything. I think the guy that recommended me this method must have got something wrong? Or perhaps I am simply incompetent:
>
> import mechanize
> import urllib
> import json
> def getData():
>      post_url = "http://www.tweetnaps.co.uk/leaderboards/leaderboard_json/current_week"
>      browser = mechanize.Browser()
>      browser.set_handle_robots(False)
>      browser.addheaders = [('User-agent', 'Firefox')]
>
>      #These are the parameters you've got from checking with the aforementioned tools
>      parameters = {'page' : '1',
>                    'rp' : '50',
>                    'sortname' : 'total_pl',
>                    'sortorder' : 'desc'
>                   }
>      #Encode the parameters
>      data = urllib.urlencode(parameters)
>      trans_array = browser.open(post_url,data).read().decode('UTF-8')
>
>      text1 = json.loads(trans_array)
>      print text1['rows'][0]['id']  #play around with these values to access different data..
>
> getData()
>
> He told me to "#play around with these values to access different data.." really cant get anything out of this, any ideas?
>
> Many thanks AEA
>
I've just tried it. It prints "1048".

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Accessing Json data (I think I am nearly there) complete beginner Andrew Edwards-Adams <aeaprog@gmail.com> - 2013-05-23 09:09 -0700
  Re: Accessing Json data (I think I am nearly there) complete beginner Andrew Berg <bahamutzero8825@gmail.com> - 2013-05-23 11:40 -0500
    Re: Accessing Json data (I think I am nearly there) complete beginner Andrew Edwards-Adams <aeaprog@gmail.com> - 2013-05-23 09:58 -0700
      Re: Accessing Json data (I think I am nearly there) complete beginner Andrew Berg <bahamutzero8825@gmail.com> - 2013-05-23 12:59 -0500
      Re: Accessing Json data (I think I am nearly there) complete beginner Andrew Berg <bahamutzero8825@gmail.com> - 2013-05-23 13:11 -0500
        Re: Accessing Json data (I think I am nearly there) complete beginner Andrew Edwards-Adams <aeaprog@gmail.com> - 2013-05-23 11:19 -0700
          Re: Accessing Json data (I think I am nearly there) complete beginner Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-05-23 19:56 +0100
            Re: Accessing Json data (I think I am nearly there) complete beginner Andrew Edwards-Adams <aeaprog@gmail.com> - 2013-05-23 14:30 -0700
  Re: Accessing Json data (I think I am nearly there) complete beginner MRAB <python@mrabarnett.plus.com> - 2013-05-23 17:53 +0100

csiph-web