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

  • Home
  • SEARCH
  • 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 7868769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:06:22+00:00 2026-06-03T01:06:22+00:00

Here is some code: from lxml import etree url = ‘http://www.google.com/ig/api?stock=aapl’ data = etree.parse(url)

  • 0

Here is some code:

from lxml import etree
url = 'http://www.google.com/ig/api?stock=aapl'
data = etree.parse(url) 
root = data.getroot()
finance = root[0]


def clean(var, num):
    var = str(finance[num].attrib).split("'")[-2]
    print var

I would like to return the variable as an object that I can call later.

I know what the problem is – the str() – but don’t know how to fix it as working with the variable directly doesn’t allow me to to do the necessary manipulations with .attrib and .split

  • 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-03T01:06:23+00:00Added an answer on June 3, 2026 at 1:06 am

    Assuming you want to gather information from XML, do:

    data = dict()
    for elem in finance:
        data[elem.tag] = elem.attrib['data']
    

    You will get a dictionary in data variable like:

    {'symbol': 'AAPL', 'company': 'Apple Inc.', 'currency': 'USD', 'volume': '19145182' ... }
    

    And you’ll be able to access particular pieces of info:

    print data['company']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got some sample code from the net here: http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class That works fine. It
here is some code: from Tkinter import * class Main(object): def __init__(self): self.console =
I'm using some code from here to determine when determining when the last finger
I tried following some of the code from here and here , but I
I'm building a python application from some source code I've found Here I've managed
I am trying to get some form data from POST method. Here's the code
Here's some code from an FTP application I'm working on. The first method comes
Here is some code copied from Thinking in C++ Vol1 Chapter 10. #include <iostream>
For example, here is some code from django.templates.loader.app_directories.py.[1] try: yield safe_join(template_dir, template_name) except UnicodeDecodeError:
Here's some code from Richard Jones' Blog : with gui.vertical: text = gui.label('hello!') items

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.