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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:45:04+00:00 2026-05-24T16:45:04+00:00

Here is the example: I am trying to grab a series of XML pages,

  • 0

Here is the example:
I am trying to grab a series of XML pages, and then extract data from them.

It downloads each individual page, as the while loop was designed to do but the tester() function prints the data from the first file it downloads V number of times despite it downloading and clearing the file after each time it loops through.

This is killing me what am I doing wrong?

def tester():
    with open('raw.txt') as myFile:
        test = linecache.getline('raw.txt', 12)
        print test
        test = ""
        myFile.close

def grab_data(Year, rcvote):
    link = "XXX/%s/roll%s.xml" % (Year, rc)
    site = urllib2.urlopen(link)
    localFile = open('raw.txt', 'w')
    localFile.write(site.read(100000))
    localFile.close()
    tester()


while (V !=0):
    rc = str(V)
    if (len(rc) == 2):
        rc = "0%s" % (rc)
    elif (len(rc) == 1):
        rc = "00%s" % (rc)
    else:
        rc = rc
    grab_data(Year, rc)
    V = V - 1
  • 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-05-24T16:45:06+00:00Added an answer on May 24, 2026 at 4:45 pm

    The problem is the linecache module. It assumes that same-named files are the same.

    But why write the data to a file just to read it again anyway?

    def tester(text):
        line12 = text.splitlines()[11]
        print line12
    
    def grab_data(year, rcvote):
        link = "XXX/%s/roll%03d.xml" % (year, rcvote)
        site = urllib2.urlopen(link)
        tester(site.read(100000))
    
    while v:
        grab_data(year, rc)
        v -= 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to grab each URL parameter and display them from first to last,
i am trying one example from Here for ontouch image zoom and touch on
I'm trying to grab data from a JSON on an external site but the
I can't post the exact data i'm trying to extract but here's a basic
So I am trying to work through the example here: http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/SurfaceViewOverlay.html and on the
I'm a newbie to sql and am trying to follow this example here: http://net.tutsplus.com/tutorials/php/a-better-login-system/
Here's an example of what I'm trying to do. User = (name,dob,rank,score) -> {
Here's an example of what I'm trying to figure out. I have a couple
I'm trying to implement the example outlined here: http://www.codeproject.com/Articles/30994/Introduction-to-WPF-Templates The author states The ContentPresenter
I am trying to read this .csv file and here is an example of

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.