-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcgv.py
More file actions
87 lines (69 loc) · 2.84 KB
/
cgv.py
File metadata and controls
87 lines (69 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time
import pandas as pd
options = Options()
options.add_argument("--start-maximized")
options.add_experimental_option("detach", True)
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=options)
baseurl = "https://m.cgv.co.kr/WebApp/GiftV5/storeCategory.aspx?CategoryIdx=4"
driver.get(baseurl)
time.sleep(1)
data = []
def process_items(items, cate):
for i in range(len(items)):
items = driver.find_elements(By.CLASS_NAME, "img_wrap")
titles1 = driver.find_elements(By.CLASS_NAME, "list_type0_title")
product_name = titles1[i].text
items[i].click()
time.sleep(1)
# 이미지 src 추출
image_tag = driver.find_element(By.CLASS_NAME, "swiper-slide").find_element(By.TAG_NAME, "img")
image_src = image_tag.get_attribute('src') # img 태그의 src 속성 추출
price = driver.find_element(By.CLASS_NAME, "store_deatail_sale_price").text
info = driver.find_element(By.CLASS_NAME, "store_deatail_add_info")
info_dict = {}
detail = driver.find_element(By.CLASS_NAME,"store_detail_product_introduce").text
for dt, dd in zip(info.find_elements(By.TAG_NAME, "dt"), info.find_elements(By.TAG_NAME, "dd")):
info_dict[dt.text] = dd.text
# 필요한 정보만 추출
item_data = {
"Product Name": product_name,
"Price": price,
"Composition": info_dict.get("상품구성"),
"Expiration": info_dict.get("유효기간"),
"Origin": info_dict.get("원산지"),
"Detail": detail,
"Image": image_src # 이미지 src 추가
}
data.append(item_data)
driver.back()
driver.find_element(By.LINK_TEXT, cate).click()
time.sleep(1)
# 세트 메뉴
cate1 = "콤보"
items1 = driver.find_elements(By.CLASS_NAME, "img_wrap")
process_items(items1, cate1)
cate2 = "팝콘"
driver.find_element(By.LINK_TEXT, "팝콘").click()
time.sleep(1)
items2 = driver.find_elements(By.CLASS_NAME, "img_wrap")
process_items(items2, cate2)
cate3 = "음료"
driver.find_element(By.LINK_TEXT, "음료").click()
time.sleep(1)
items3 = driver.find_elements(By.CLASS_NAME, "img_wrap")
process_items(items3, cate3)
cate4 = "스낵"
driver.find_element(By.LINK_TEXT, "스낵").click()
time.sleep(1)
items4 = driver.find_elements(By.CLASS_NAME, "img_wrap")
process_items(items4, cate4)
# DataFrame으로 변환하여 CSV로 저장
df = pd.DataFrame(data)
df.to_csv("cgv_food_info.csv", index=False, encoding='utf-8-sig')
print(df)