manage.py:无法连接到X服务器

Nav*_*ava 3 django django-admin pyqt4 django-manage.py

我使用PyQt4.QtWebkit来抓取我的django应用程序中的网页.在生产环境中该模块无法抓取它.它会抛出错误"manage.py:无法连接到X服务器"

我的Qt班:

class Render(QWebPage):
 def __init__(self, url):
    self.app = QApplication(sys.argv)
    QWebPage.__init__(self)
    self.loadFinished.connect(self._loadFinished)
    self.mainFrame().load(QUrl(url))
    self.app.exec_()

 def _loadFinished(self, result):
    self.frame = self.mainFrame()
    self.app.quit() 
Run Code Online (Sandbox Code Playgroud)

从django-shell调用:

 r = Render(url)
Run Code Online (Sandbox Code Playgroud)

当我使用Django-shell(python manage.py shell)通过django调用这个"Render"类时,render函数会抛出错误.你能帮帮我吗?

Nav*_*ava 7

原因是"Xvfb"

我需要用xvfb(X虚拟帧缓冲区)在bash shell中运行我的python程序,

ubuntu@localhost$ xvfb-run python webpage_scrapper.py http://www.google.ca/search?q=navaspot
Run Code Online (Sandbox Code Playgroud)

它给出了结果.

现在我的要求是我需要在python中执行这个shell命令并等待tine来收集结果.我必须处理结果.

能否建议我有效地在python上执行这个命令.