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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:49:35+00:00 2026-05-16T06:49:35+00:00

I have a program that fetches info from other pages and parses them using

  • 0

I have a program that fetches info from other pages and parses them using BeautifulSoup and Twisted’s getPage. Later on in the program I print info that the deferred process creates. Currently my program tries to print it before the differed returns the info. How can I make it wait?

def twisAmaz(contents): #This parses the page (amazon api xml file)
    stonesoup = BeautifulStoneSoup(contents)
    if stonesoup.find("mediumimage") == None:
       imageurl.append("/images/notfound.png")
    else:
      imageurl.append(stonesoup.find("mediumimage").url.contents[0])

    usedPdata = stonesoup.find("lowestusedprice")
    newPdata = stonesoup.find("lowestnewprice")
    titledata = stonesoup.find("title")
    reviewdata = stonesoup.find("editorialreview")

    if stonesoup.find("asin") != None:
        asin.append(stonesoup.find("asin").contents[0])
    else:
        asin.append("None")
    reactor.stop()


deferred = dict()
for tmpISBN in isbn:  #Go through ISBN numbers and get Amazon API information for each
    deferred[(tmpISBN)] = getPage(fetchInfo(tmpISBN))
    deferred[(tmpISBN)].addCallback(twisAmaz)
    reactor.run()

.....print info on each ISBN
  • 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-16T06:49:36+00:00Added an answer on May 16, 2026 at 6:49 am

    What it seems like is you’re trying to make/run multiple reactors. Everything gets attached to the same reactor. Here’s how to use a DeferredList to wait for all of your callbacks to finish.

    Also note that twisAmaz returns a value. That value is passed through the callbacks DeferredList and comes out as value. Since a DeferredList keeps the order of the things that are put into it, you can cross-reference the index of the results with the index of your ISBNs.

    from twisted.internet import defer
    
    def twisAmazon(contents):
        stonesoup = BeautifulStoneSoup(contents)
        ret = {}
        if stonesoup.find("mediumimage") is None:
            ret['imageurl'] = "/images/notfound.png"
        else:
            ret['imageurl'] = stonesoup.find("mediumimage").url.contents[0]
        ret['usedPdata'] = stonesoup.find("lowestusedprice")
        ret['newPdata'] = stonesoup.find("lowestnewprice")
        ret['titledata'] = stonesoup.find("title")
        ret['reviewdata'] = stonesoup.find("editorialreview")
        if stonesoup.find("asin") is not None:
            ret['asin'] = stonesoup.find("asin").contents[0]
        else:
            ret['asin'] = 'None'
        return ret
    
    callbacks = []
    for tmpISBN in isbn:  #Go through ISBN numbers and get Amazon API information for each
        callbacks.append(getPage(fetchInfo(tmpISBN)).addCallback(twisAmazon))
    
    def printResult(result):
        for e, (success, value) in enumerate(result):
            print ('[%r]:' % isbn[e]),
            if success:
                print 'Success:', value
            else:
                print 'Failure:', value.getErrorMessage()
    
    callbacks = defer.DeferredList(callbacks)
    callbacks.addCallback(printResult)
    
    reactor.run()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program which fetches records from database (using Hibernate) and fills them
So I have this program that fetches a page using a short link (I
So I have this program that fetches a page using a short link (I
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that monitors debug messages and I have tried using a
I have a program that runs osql.exe from microsoft sql server tools directory and
I am trying to program an App that fetches files from a server. I
I have a program that generates some standard SQL like SELECT * FROM TEST
I have a program that I'm writing where I am using another company's library

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.