V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
m939594960
V2EX  ›  Python

Pyqt webkit 开启状态 后面的代码无法继续执行

  •  
  •   m939594960 · 2015-03-12 01:32:19 +08:00 · 2764 次点击
    这是一个创建于 3355 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这是显示 webkit的类

    class baidubro(QtCore.QObject):
        """docstring for baidubor"""
        def __init__(self):
            QObject.__init__(self)
            self.fuck='123'
            self.app = QApplication(sys.argv)
            self.webview = QWebView()  
            self.page=self.webview.page()
            self.current = "https://passport.baidu.com/v2/?reg"  
            self.frame = self.page.mainFrame()       
            QtCore.QObject.connect(self.frame,QtCore.SIGNAL('loadFinished(bool)'),self.do_do)
            self.webview.show() 
            self.frame.load(QUrl(self.current))
            sys.exit(self.app.exec_())
        def do_do(self,bool):
            url = self.frame.url()
            js="setTimeout(function (){document.getElementById('TANGRAM__PSP_4__account').value="+self.fuck+";document.getElementById('TANGRAM__PSP_4__password').value='11111';document.getElementById('TANGRAM__PSP_4__password').focus();},1800);setTimeout(function (){document.getElementById('TANGRAM__PSP_4__verifyCodeSend').click();},2800)"
            self.frame.evaluateJavaScript(js)
    

    我是这样调用的

    import baidubro
    baidubro.baidubro()
    print 'asd'
    

    发现 我只要不关掉 pyqt 创建的浏览框 后面的asd 就不会输出!
    现在想要再 浏览框开启的状态 后台获取数据 填入表单内!

    最近刚刚学的Python 问题可能有点弱智!
    以前编程都是 VB 易语言 PHP 引包 突然有点不适应。。。。

    代码不能格式化 我也是醉了!!!
    还是上图吧

    http://i2.tietuku.com/14107f3b16aebe9f.png

    调用

    http://i2.tietuku.com/47a972f0e0904e7d.png

    5 条回复    2015-03-13 06:46:40 +08:00
    csslayer
        1
    csslayer  
       2015-03-12 02:01:32 +08:00
    self.app.exec_() 直到程序退出才返回的,从这里进入 Qt 的主循环了。

    你应该把后面的功能实现在 do_do 里面,或者定义一个新的 signal emit 出去。

    而且 QApplication 的创建不应该放在 QObject 里面,建议找个 pyqt 的例子自己先从头了解一下。

    有 UI 的程序都要考虑是事件驱动的而不是纯粹的过程。
    Livid
        2
    Livid  
    MOD
       2015-03-12 02:06:53 +08:00
    @m939594960 代码的格式化目前需要从这个接口发帖:

    https://www.v2ex.com/new
    Livid
        3
    Livid  
    MOD
       2015-03-12 02:07:13 +08:00
    为你调整了一下这个帖子。现在已经可以格式化代码。
    m939594960
        4
    m939594960  
    OP
       2015-03-12 18:14:40 +08:00
    @csslayer 感谢你的回复 pyqt 的例子我也再找 还没找到! 一时半会不知道找啥 能找到例子!
    csslayer
        5
    csslayer  
       2015-03-13 06:46:40 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1207 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 23:27 · PVG 07:27 · LAX 16:27 · JFK 19:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.