-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
85 lines (63 loc) · 2.19 KB
/
Copy pathtest.py
File metadata and controls
85 lines (63 loc) · 2.19 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
import os
import csv
import requests
from bs4 import BeautifulSoup
from unicodedata import normalize
os.system("clear")
alba_url = "http://www.alba.co.kr"
res = requests.get(alba_url)
soup = BeautifulSoup(res.text, 'html.parser')
brand_list = []
def get_brand(box):
inner_list = box.find_all('a')[1:]
for inner in inner_list:
name = inner.find(
'span', {"class": "company"}).find('strong').get_text()
url = inner['href']
brand_list.append({'name': name, 'url': url, 'info': []})
def get_hire_info_url(brand):
res = requests.get(brand['url'])
soup = BeautifulSoup(res.text, 'html.parser')
# check_page
page_size = soup.find(
'p', {"class": "jobCount"}).find('strong').get_text()
return brand['url'] + f"/job/brand/?pagesize={page_size}"
def get_hire_info(hire):
try:
hire_info = hire.find_all('td')
place = normalize('NFKD', hire_info[0].get_text())
title = hire_info[1].find('a').find(
'span', {"class": "company"}).get_text()
time = hire_info[2].get_text()
pay = hire_info[3].find('span', {"class": "payIcon"}).get_text(
) + hire_info[3].find("span", {"class": "number"}).get_text()
date = hire_info[4].get_text()
return [place, title, time, pay, date]
except:
return []
def save_to_file(brand):
file = open(f"test/{brand['name']}.csv", "w")
writer = csv.writer(file)
writer.writerow(["place", "title", "time", "pay", "date"])
for info in brand['info']:
writer.writerow(info)
return
box_list = soup.find('div', {"id": "MainSuperBrand"}).find(
'ul', {"class": "goodsBox"}).find_all('li')
for box in box_list:
get_brand(box)
for brand in brand_list:
try:
url = get_hire_info_url(brand)
res = requests.get(url)
soup = BeautifulSoup(res.text, 'html.parser')
try:
hire_list = soup.find('div', {"id": "NormalInfo"}).find(
'table').find('tbody').find_all('tr', {"class": ""})
except:
hire_list = []
for hire in hire_list:
brand['info'].append(get_hire_info(hire))
save_to_file(brand)
except:
pass