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


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

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



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

def thread_run():

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


    #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)

        

    

    

#thread_run()


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


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





일단 아까 올린 글에서 run 부분은 첫 시작 땜에 한거긴 한데 일단 주석 처리 해뒀음


그리고 스타트 부분은 함수 밖으로 빼라고 해서 일단 저렇게 뺐는데


맞게 한건지 모르겠다..