import time


import threading


import openpyxl

import win32com.client

import requests

from bs4 import BeautifulSoup

 


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

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

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

#excel.Visible = True


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

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


#print(html)

#print(title_list)

wb = openpyxl.Workbook()

sheet1 = wb.active






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


def thread_run():

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

    

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

        print(idx, title.text)

        list =[idx, title.text]

        sheet1.append(list)

        

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

     

thread_run()



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











현재 네이버 급상승 검색어 1~20위 긁어 와서 엑셀에 저장하는거 하는데


이게 실시간 급상승 검색어 다 보니 시간마다 순위가 변하잖아 


그래서 일정 주기마다 쓰레드 타이머 줘서 긁어 오려고 했는데


계속 엑셀이랑 콘솔에는 첨에 크롤링한 데이터만 읽어 오거나 엑셀에 저장 되는데



이거 쓰레드 위치 잘못 준거임???