ubuntu 11.04中的xvfb运行错误


问题内容

我的任务是在Python中使用无头Webkit(PyQt4.QtWebkit)来抓取Google搜索结果。该模块使用PyQt4可以很好地抓取结果。我应该在Amazon
ec2中执行此脚本。因此,我必须使用Xvfb(ec2中没有x服务器)。

同时,我的模块必须在循环中执行。因此,它在某些迭代中工作正常。在某些循环中,模块运行到 “ xvfb-run:错误:Xvfb无法启动”

应该如何解决?

这是我的循环:

for i in range(10):
    try:
        query_dict["start"] = i * 10
        url = base_url + ue(query_dict)
        flag = True
        while flag:
            parsed_dict = main(url)
            time.sleep(8.4)
            flag = False
    except:
        pass

main(url):

def main(url):
    cmd = "xvfb-run python /home/shan/temp/hg_intcen/lib/webpage_scrapper.py"+" "+str(url)
    print "Cmd EXE:"+ cmd
    proc = subprocess.Popen(cmd,shell=True,stdin=subprocess.PIPE,stdout=subprocess.PIPE)
    proc.wait()
    sys.stdout.flush()
    result = proc.stdout.readlines()
    print "crawled: ",result[1]
    return result

webpage_scrapper将使用pyqt4获取所有html结果。如何避免xvfb循环失败?


问题答案:

您需要为添加--auto-servernum参数xvfb- run。否则,它将尝试Xvfb在同一显示器上生成(默认情况下为:99),如果您已经在运行一个显示器,它将失败。