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 9117927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:00:56+00:00 2026-06-17T05:00:56+00:00

I am trying to get the pricing information about devices from a website which

  • 0

I am trying to get the pricing information about devices from a website which uses javascripts to load the data. I am getting the data in a JSON dictionary structure. Below is the code I am using:

# -*- coding: cp1252 -*-
import csv
import urllib2
import sys
import time
import re
import json
from bs4 import BeautifulSoup
from itertools import islice
from pprint import pprint

page = urllib2.urlopen('http://www.vodafone.de/privat/tarife/red-smartphone-tarife.html').read()
soup = BeautifulSoup(page)
x = [None]*1000

i = 0
j = 0
k = 0
scripts = soup.find_all('script')
script = next(s.text for s in scripts if s.string and 'window.rates' in s.string)
datastring = script.split('phones=')[1].split(';window.')[0]
datastring = re.sub(ur'([{,])([a-z]\w*):', ur'\1"\2":', datastring)
data = json.loads(datastring)

for d in data:
    for j in data[d]:
        pprint(data[d]['name']) 
        x[i] = data[d]['name']
        i = i + 1

This part gives me the list of devices from the web page.

However, when I use the same method to get the pricing information(below mentioned) which is one more level inside in the JSON data dictionary, I get a TypeError: string indices must be integers –

for d in data:
    for j in data[d]:
        for k in data[d][j]:
            pprint(data[d][j][k]) 
            x[i] = data[d][j][k]
            i = i + 1

Here is the snippet of JSON data structure which I am scraping and from which I need to extract information:

{u'deliveryTime': u'Lieferbar innerhalb 48 Stunden',
 u'image': u'/images/m707491_300465.jpg',
 u'name': u'BlackBerry Bold 9900',
 u'sku1104261': {u'e': u'169.90', u'p': u'prod974431'},
 u'sku1444275': {u'e': u'129.90', u'p': u'prod974431'},
 u'sku1444283': {u'e': u'89.90', u'p': u'prod974431'},
 u'sku1444286': {u'e': u'49.90', u'p': u'prod974431'},
 u'sku1444291': {u'e': u'49.90', u'p': u'prod974431'}}
{u'deliveryTime': u'Vorauss. verfügbar ab Mitte Januar',
 u'image': u'/images/m1327474_300658.jpg',
 u'name': u'HTC One X+ mit limitiertem Beats-Headset',
 u'sku1444277': {u'e': u'249.90', u'p': u'prod1624433'},
 u'sku1444285': {u'e': u'119.90', u'p': u'prod1624433'},
 u'sku1444287': {u'e': u'99.90', u'p': u'prod1624433'},
 u'sku1444292': {u'e': u'99.90', u'p': u'prod1624433'},
 u'sku1474223': {u'e': u'399.90', u'p': u'prod1624433'}}

Please help me in solving this issue.

  • 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-17T05:00:57+00:00Added an answer on June 17, 2026 at 5:00 am

    According to JSON structure you’ve posted, it should be something like this:

    price = 0
    for key, value in data.items():
        if key.startswith(u'sku') and isinstance(value, dict): 
            price += value.get(u'e', 0)
    

    Actually, few basic concepts here:

    • validate that you have needed keys (skipping keys not starting with “sku”)
    • validate that sub-keys are dicts
    • use .get() method for dicts instead of direct-referencing. this method allows you to specify default value that will be returned if there is no such key in dict (and no exceptions will be rised)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying get the data from my database but i am not getting
When trying get in memcache client, getting the below excepton. Caused by: java.io.IOException: com.fet.myclass.webservice.data.DataList
So i am trying get 2 div-containers which both should contain centered text (Both
I'm trying get the visible portion of UIImage from an UIImageView . UIImageView takes
I have a table which I'm trying to do a pricing list, that auto-computes
Trying to get JQuery to post JSON to a server: $.ajax({ url: /path/to/url, type:
I am trying get Javascript popup calendar control to work which doesnt work. I
I'm trying a simple regex on a string for pricing information, but my preg_match_all
Trying to use modules in Yii and want to get access from main controller
I am trying get all maping information for a specific workspace. When I try

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.