본문 바로가기

코딩 이야기/사이드 프로젝트 이야기

초미니 프로젝트 - 단어 크롤러 #2

반응형

이 프로젝트는 망했다.

 아니 글을 올린지 얼마 안되서 망했다고? 라고 하긴 그렇고, 그냥 만들다가 너무 재미가 없어질 것 같아서 관뒀다. 기본적인 기능은 일단 다 있는 상태이긴하다. 단어 횟수 구하는 정도이지만, 원래 한 단어를 html페이지 안에서 검색하면 횟수와 주로 나오는 앞 뒤 단어까지 할려했지만, 완성한다해도 재밌을 것 같다는 생각은 안들어서 그냥 급하게 마무리했다. 애초에 너무 단기간에 끝날만한 걸로 프로젝트를 잡기도 했고, 아무튼 다시 내가 흥미를 느낄만한 프로젝트를 좀 생각해봐야겠다. 

 

import sys
from PyQt5.Qt import *
import requests
from bs4 import BeautifulSoup
import time

class Mainform(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("")
        self.resize(500, 500)

        toplayout = QHBoxLayout()
        buttonlayout = QGridLayout()
        mainlayout = QVBoxLayout()

        pixmap = QPixmap("img/word scoller.png")
        lbl_img = QLabel()
        lbl_img.setPixmap(pixmap)
        lbl_img.setMaximumWidth(400)
        lbl_img.setMaximumHeight(300)
        toplayout.addWidget(lbl_img)

        self.pathlbl = QLabel("크롤링 할 주소")
        buttonlayout.addWidget(self.pathlbl,0,0)

        self.LineEdit_path = QLineEdit()
        self.LineEdit_path.setPlaceholderText("크롤링 할 주소를 입력하세요.")
        self.LineEdit_path.setMaximumWidth(200)
        buttonlayout.addWidget(self.LineEdit_path,0,1)

        self.wordlbl = QLabel("크롤링 할 단어")
        buttonlayout.addWidget(self.wordlbl,1,0)

        self.LineEdit_word = QLineEdit()
        self.LineEdit_word.setPlaceholderText("크롤링 할 단어를 입력하세요.")
        self.LineEdit_word.setMaximumWidth(200)
        buttonlayout.addWidget(self.LineEdit_word,1,1)

        self.combutton = QPushButton("완료")
        self.combutton.setMaximumWidth(120)
        self.combutton.clicked.connect(self.crolling)
        buttonlayout.addWidget(self.combutton,2,0)

        mainlayout.addLayout(toplayout)
        mainlayout.addLayout(buttonlayout)
        self.setLayout(mainlayout)

    def crolling(self):
        msg = QMessageBox()
        count = 0
        path = requests.get(self.LineEdit_path.text()).text.split()
        word = self.LineEdit_word.text()
        for i in path:
            if i == word:
                count += 1
        msg.setText("단어 횟수:" + str(count))
        msg.exec_()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    form = Mainform()
    form.show()
    sys.exit(app.exec_())
반응형