import time


import threading

import openpyxl

import win32com.client

import requests

from bs4 import BeautifulSoup


excel = win32com.client.Dispatch("Excel.Application")

#excel.Visible = True


#print(title_list)

wb = openpyxl.Workbook()

sheet1 = wb.active



#excel_file = excel.Workbooks.Open('C:/Users/thkim/Desktop/test3.xlsx')

def thread_run():

    print('=========================================================')

    

    

    html = requests.get('https://www.naver.com/').text

    soup = BeautifulSoup(html, 'html.parser')

    


    #title_list = soup.select('.PM_CL_realtimeKeyword_rolling')

    title_list = soup.select('.PM_CL_realtimeKeyword_rolling span[class*=ah_k]')


    #print(html)


    

    for idx, title in enumerate(title_list, 1):

        print(idx, title.text)

        list =[idx, title.text]

        sheet1.append(list)

        

    threading.Timer(10, thread_run).start()


thread_run()


wb.save('C:/Users/thkim/Desktop/test3.xlsx')






일단은 내가 쓰레드 런 하는 부분에서


계속 엑셀에 쓰고 출력하는 부분만 해놨기에


그 부분은 수정을 했는데


댓으로 쓰레드런하고 스타트 하는 부분에 대한 건 아직 이해 못해서 조금 더 찾아 보는 중...



일단 위 방법대로 하면 출력값들이 조금씩 달라 지긴 하는데...


음....뭔가 부족한 느낌이네....


조금더 찾아 보겠음....



그 전글 : 


https://gall.dcinside.com/board/view/?id=programming&no=1215588