Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8787897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:00:41+00:00 2026-06-13T22:00:41+00:00

I currently have a script that is supposed to fetch and return the number

  • 0

I currently have a script that is supposed to fetch and return the number of clicks a Bit.ly link has. I start out by gathering and reading the data from a Bitly url, which I appear to be doing correctly.

    bitly_data = "https://api-ssl.bitly.com/v3/link/clicks?access_token=ACCESS_TOKEN&link=http://bit.ly/"+link
    src = urllib2.urlopen(bitly_data)
    src = src.read()

When link is something such as TY8lnd, src is a string that looks something like

{“status_code”: 200, “data”: {“units”: -1, “tz_offset”: -4, “unit”:
“day”, “link_clicks”: 535}, “status_txt”: “OK”}

I now want to parse this string to get just the numerical value after link_clicks. I figured the best way to do this was by making two splits.

    src=src.split('clicks": ')
    src = str(src[1])
    clicks = src.split('}, "status')
    clicks = clicks[0]

When I run this, clicks does, ultimately, equal the correct number and only that. However, Terminal returns an IndexError for the line src = str(src[1]). I tried getting rid of the str() but this had no effect. An understanding as to why I am getting this error despite the end value being corrected would be greatly appreciated.

Here is the Traceback in its entirety:

Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1701, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1689, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1687, in wsgi_app
    response = self.full_dispatch_request()
  File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1360, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1358, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Library/Python/2.7/site-packages/Flask-0.9-py2.7.egg/flask/app.py", line 1344, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/Zach/Dropbox/bitly/bit.py", line 35, in settings
    src = str(src[1])
IndexError: list index out of range

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:00:42+00:00Added an answer on June 13, 2026 at 10:00 pm

    This response is json, as such, decode the json instead of trying to parse the string.

    >>> import json
    >>> resp = '{"status_code": 200, "data": {"units": -1, "tz_offset": -4, "unit": "day", "link_clicks": 535}, "status_txt": "OK"}'
    >>> resp_object = json.loads(resp)
    >>> resp_object and resp_object.get('data', {}).get('link_clicks', 0) or 0
    535
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have a script that deletes old log files and then takes any
I currently have a script that scrapes proxies off websites, but I'm just wondering
Currently we have a script that does maven build + tomcat deploy. Deploying to
I currently have a ajax script that dynamically builds two select boxes enabled with
I currently have a python script that runs every few minutes and picks up
I currently have a Perl CGI script that parses incoming XML requests using XML::Simple
I have a batch script that calls a process and currently it waits for
I'm modifying a PHP script that I have and it is currently outputting a
I'm currently building my own login script and have noticed that most append the
I currently have a number of Python scripts that help prep a staging area

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.