Wadis_funding / app.py
aliceblue11's picture
Update app.py
b2c4288 verified
import time
import random
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
import gradio as gr
# 스크롤을 위한 함수
def scroll_down(driver):
# 페이지 끝까지 스크롤
driver.find_element(By.TAG_NAME, "body").send_keys(Keys.END)
time.sleep(random.uniform(1, 2))
# 100개의 상품 정보를 수집하는 함수
def get_funding_items():
# Chrome 옵션 설정
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless") # 브라우저 창을 띄우지 않음
chrome_options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36")
# ChromeDriver 실행
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
# 와디즈 페이지 접속
driver.get('https://www.wadiz.kr/web/wreward/category?order=recommend')
# 페이지 로딩 대기
time.sleep(random.uniform(2, 4))
# 스크롤 및 데이터 수집
items = []
while len(items) < 100:
# 페이지 로딩을 위해 잠시 대기
time.sleep(random.uniform(1, 2))
# 스크롤 다운
scroll_down(driver)
# 상품 정보 수집
product_cards = driver.find_elements(By.CLASS_NAME, 'HomeHorizontalCard_content__1eT1m')
for card in product_cards:
if len(items) >= 100:
break
try:
title = card.find_element(By.CLASS_NAME, 'Title_title__3kHxQ').text
maker = card.find_element(By.CLASS_NAME, 'MakerWrapper_makerName__131I-').text
funding_info = card.find_element(By.CLASS_NAME, 'InfoStringWrapper_infoString__2HtEW').text
items.append({
'title': title,
'maker': maker,
'funding_info': funding_info
})
except Exception as e:
continue
driver.quit()
return items
# Gradio 인터페이스 생성
def display_items():
items = get_funding_items()
return items
# Gradio UI 설정
interface = gr.Interface(fn=display_items, inputs=[], outputs="json", title="와디즈 펀딩 정보 가져오기")
if __name__ == "__main__":
interface.launch(share=True)