如何将scrapy集成到PyQT5中

时间:2019-03-17 00:42:12

标签: python scrapy pyqt5

所以我很困惑,我有一个简单的应用程序,还有一个简单的gui应用程序

文件夹结构如下

enter image description here

当前我可以通过以下文件执行脚本

app.py

import os
from subprocess import call



def main():
    owl = os.path.abspath('scrape')
    myOwl = '/pythonwork/bbbscrap2/scrape'
    # print(myOwl)
    # print(os.path.abspath(cwd))

    ourPath = ['scrapy','crawl', 'yellow']
    name = "yellow"
    call(["scrapy", "crawl", "{0}".format(name)], cwd=myOwl)

if __name__ == "__main__" :
    main()

但是,在构建GUI界面并运行脚本时,它们将是一个屏幕日志,显示执行期间发生的情况。我不确定如何将scrapy集成到pyqt5中。这就是我目前拥有的

enter image description here

gui.py

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QMessageBox, QDesktopWidget, QGridLayout
from PyQt5.QtGui import QIcon

class App(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):                
        self.resize(450, 250)
        self.center()  
        self.setWindowTitle('Yellow Page Scrapper')    
        title = QLabel('Input Search Item: ')
        titleEdit = QLineEdit()
        grid = QGridLayout()
        grid.setSpacing(2)
        grid.addWidget(title, 1, 0)
        grid.addWidget(titleEdit, 1, 1)
        self.setLayout(grid) 
        self.show()


    def center(self):    
        qr = self.frameGeometry()
        cp = QDesktopWidget().availableGeometry().center()
        qr.moveCenter(cp)
        self.move(qr.topLeft())


    def closeEvent(self, event):
        reply = QMessageBox.question(self, 'Message',
            "Are you sure to quit?", QMessageBox.Yes | 
            QMessageBox.No, QMessageBox.No)
        if reply == QMessageBox.Yes:
            event.accept()
        else:
            event.ignore()        


if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = App()
    sys.exit(app.exec_())

TLDR

如何在PyQT5 GUI界面上显示抓取日志?

0 个答案:

没有答案