-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheshop_crawler.py
More file actions
44 lines (32 loc) · 1.16 KB
/
eshop_crawler.py
File metadata and controls
44 lines (32 loc) · 1.16 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
from selenium.common.exceptions import NoSuchElementException
# result sample
# ...
# ["마리오파티슈퍼스타즈"] =
# {
# "price": 64800
# "sale_price": 54000 (None, if not sale period)
# },
# ...
def trim_price(string):
return int(string.replace("₩", "").replace(",", ""))
def eshop_crawl(driver):
result = dict()
# load page
driver.get("https://store.nintendo.co.kr/games")
driver.find_element_by_class_name("popup-close").click()
# search game list
game_list = driver.find_elements_by_class_name("category-product-item")
for game in game_list:
game_data = dict()
# name & url
url_text = game.find_element_by_class_name("category-product-item-title-link")
# price
price_list = game.find_elements_by_class_name("price")
if len(price_list) == 1:
game_data["price"] = trim_price(price_list[0].text)
game_data["sale_price"] = None
else:
game_data["price"] = trim_price(price_list[1].text)
game_data["sale_price"] = trim_price(price_list[0].text)
result[url_text.text.replace(" ", "")] = game_data
return result