-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurfit.py
More file actions
77 lines (58 loc) · 2.16 KB
/
Copy pathsurfit.py
File metadata and controls
77 lines (58 loc) · 2.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
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
"""
Surfit Crawler
1. get post list page html from Surfit
2. parse url, title, description from html
3. insert url, title, description, category into mysql
"""
from crawler.surfit.set_up_data import surfit_url_list
from crawler.utils.utils import (
set_chrome_driver,
append_data,
initialize_jagged_list,
one_cycle_of_crawling, one_cycle_of_crawling_urls_by_category,
)
from crawler.utils.utils_db import insert_into_database
from crawler.utils.utils_csv import save_to_csv
from crawler.surfit.set_up_data import category_list
def surfit_crawler_with_db():
driver = set_chrome_driver()
posts = []
initialize_jagged_list(list_name=posts, list_length=4)
for i, surfit_url in enumerate(surfit_url_list):
one_cycle_of_crawling(driver, surfit_url, posts, i)
items = append_data(
urls=posts[0], titles=posts[1], descriptions=posts[2], category=posts[3]
)
insert_into_database(
items=items, user="root", passwd="cool", host="127.0.0.1", db="test_db"
)
driver.quit()
def surfit_crawler_with_csv():
driver = set_chrome_driver()
posts = []
initialize_jagged_list(list_name=posts, list_length=5)
# 과정: 크롤링 -> items에 저장 -> csv 파일에 저장
column = ["url", "title", "description", "category", "image"]
for i, surfit_url in enumerate(surfit_url_list):
one_cycle_of_crawling(driver, surfit_url, posts, i)
items = append_data(
urls=posts[0], titles=posts[1], descriptions=posts[2], category=posts[3], image=posts[4]
)
posts = [[], [], [], [], []] # 리스트 초기화
save_to_csv(
file_name=f"csv_files/{category_list[i]}.csv", column=column, data=items
)
driver.quit()
def surfit_link_crawler_with_csv():
driver = set_chrome_driver()
for i, surfit_url in enumerate(surfit_url_list):
urls = one_cycle_of_crawling_urls_by_category(
driver=driver, url=surfit_url
)
save_to_csv(
file_name=f"url_csv_files/{category_list[i]}.csv", column=[], data=urls
)
print("완료")
driver.quit()
if __name__ == "__main__":
surfit_crawler_with_csv()