aliceblue11 commited on
Commit
d675f88
·
verified ·
1 Parent(s): 7db8202

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -0
app.py ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import time
2
+ import random
3
+ from selenium import webdriver
4
+ from selenium.webdriver.common.by import By
5
+ from selenium.webdriver.chrome.service import Service
6
+ from selenium.webdriver.common.keys import Keys
7
+ from webdriver_manager.chrome import ChromeDriverManager
8
+ import gradio as gr
9
+
10
+ # 스크롤을 위한 함수
11
+ def scroll_down(driver):
12
+ # 페이지 끝까지 스크롤
13
+ driver.find_element(By.TAG_NAME, "body").send_keys(Keys.END)
14
+ time.sleep(random.uniform(1, 2))
15
+
16
+ # 100개의 상품 정보를 수집하는 함수
17
+ def get_funding_items():
18
+ # Chrome 옵션 설정
19
+ chrome_options = webdriver.ChromeOptions()
20
+ chrome_options.add_argument("--headless") # 브라우저 창을 띄우지 않음
21
+ 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")
22
+
23
+ # ChromeDriver 실행
24
+ driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=chrome_options)
25
+
26
+ # 와디즈 페이지 접속
27
+ driver.get('https://www.wadiz.kr/web/wreward/category?order=recommend')
28
+
29
+ # 페이지 로딩 대기
30
+ time.sleep(random.uniform(2, 4))
31
+
32
+ # 스크롤 및 데이터 수집
33
+ items = []
34
+ while len(items) < 100:
35
+ # 페이지 로딩을 위해 잠시 대기
36
+ time.sleep(random.uniform(1, 2))
37
+
38
+ # 스크롤 다운
39
+ scroll_down(driver)
40
+
41
+ # 상품 정보 수집
42
+ product_cards = driver.find_elements(By.CLASS_NAME, 'HomeHorizontalCard_content__1eT1m')
43
+
44
+ for card in product_cards:
45
+ if len(items) >= 100:
46
+ break
47
+ try:
48
+ title = card.find_element(By.CLASS_NAME, 'Title_title__3kHxQ').text
49
+ maker = card.find_element(By.CLASS_NAME, 'MakerWrapper_makerName__131I-').text
50
+ funding_info = card.find_element(By.CLASS_NAME, 'InfoStringWrapper_infoString__2HtEW').text
51
+ items.append({
52
+ 'title': title,
53
+ 'maker': maker,
54
+ 'funding_info': funding_info
55
+ })
56
+ except Exception as e:
57
+ continue
58
+
59
+ driver.quit()
60
+ return items
61
+
62
+ # Gradio 인터페이스 생성
63
+ def display_items():
64
+ items = get_funding_items()
65
+ return items
66
+
67
+ # Gradio UI 설정
68
+ interface = gr.Interface(fn=display_items, inputs=[], outputs="json", title="와디즈 펀딩 정보 가져오기")
69
+
70
+ if __name__ == "__main__":
71
+ interface.launch()