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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:53:01+00:00 2026-06-17T06:53:01+00:00

I have a script, that works fine: if __name__ == ‘__main__’: app = QApplication(sys.argv)

  • 0

I have a script, that works fine:

if __name__ == '__main__':
    app = QApplication(sys.argv)
    bot = GBot()
    bot.search('hot tea', num=20)
    if signal.signal(signal.SIGINT, signal.SIG_DFL):
        sys.exit(app.exec_())
    app.exec_()

When I call search(), program starts working, and and loads website:

def _loadFinished(self, ok):
        current_url = self.page().currentFrame().url().toString()
        if str(current_url).endswith('.com/'):
            self.home_search()
        else:
            self.get_links_text_from_page()
            
        if self.count >= self.desired_number_of_results:
            self.close()

After load finished 1 time, it checks for another condition and desides what to do next.
At the end, after program loads multiple websites. Desired data collected in variable called self.results.

So my question is how I can return result from search(), by checking condition of loadFinished().

Another words, I need to come up with some sort of algorithm that will check if loadFinished will not load any other websites, and than search() function will return desired variable. I was thinking to create another variable self.result = False than change the condition in loadFinished() and in search() place everything in while loop, and after that return result. But it doesn’t work…

search()

def search(self, keyword, num=None, output=None):
    self.keyword = keyword
    if output is "json":
    # need to return `self.results` ONLY after program finished. because before that,
    # this variable is empty
    self.load('somewebsite.com')
    pass
  • 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-17T06:53:02+00:00Added an answer on June 17, 2026 at 6:53 am

    Looks like you could use a generator here. In this QWebView example, loadWebsites is called until StopIteration is raised, in which case procDone is emitted with the number of loaded websites. The output for that signal is captured in the slot on_procDone. (The output in this case is 3, because of ["http://www.example.com"]*3):

    #!/usr/bin/env python
    #-*- coding:utf-8 -*-
    
    from PyQt4 import QtCore, QtGui, QtWebKit, QtNetwork
    
    class myWindow(QtWebKit.QWebView):
        procDone = QtCore.pyqtSignal(int)
    
        def __init__(self, parent=None):
            super(myWindow, self).__init__(parent)
    
            self.websites      = iter(["http://www.example.com"]*3)
            self.websitesTotal = 0
    
            self.loadFinished.connect(self.on_loadFinished)
            self.procDone.connect(self.on_procDone)
    
            self.loadWebsites()
    
        def loadWebsites(self):
            try:
                website = self.websites.next()
    
            except StopIteration:
                self.procDone.emit(self.websitesTotal)
    
            else:
                self.load(QtCore.QUrl(website))
    
        @QtCore.pyqtSlot(bool)
        def on_loadFinished(self, ok):
            self.websitesTotal += 1
            print "Loaded: {0}".format(self.url().toString())
            self.loadWebsites()
    
        @QtCore.pyqtSlot(int)
        def on_procDone(self, total):
            print "Total of websites: {0}".format(total)
            self.websitesTotal = 0
    
    if __name__ == "__main__":
        import sys
    
        app = QtGui.QApplication(sys.argv)
        app.setApplicationName('myWindow')
    
        main = myWindow()
        main.show()
    
        sys.exit(app.exec_())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jQuery script that works fine: $(select).change(function () { var finalPrice =
I have a script on here that works fine in FF14 and Chrome20. A
I have the following code that works fine in IE: <HTML> <BODY> <script language=JavaScript>
We have a ubuntu test server that this simple script works fine on where
I have this Greasemonkey script that works fine in the Fiddle. It's designed to
I have a jquery script that works perfectly fine in all browsers except IE.
I have that works fine without Script manager. but if I add script manager
I have a script that performs some simple editing which works fine, the problem
I have a great php mySQL login script that works fine. Is ther another
I have the following script that works fine with uploadify, What i would like

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.