Skip to content

Commit 0c7d177

Browse files
committed
알바천국 웹스크랩
1 parent 2c49395 commit 0c7d177

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

homework6.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import os
2+
import csv
3+
import requests
4+
from bs4 import BeautifulSoup
5+
6+
os.system("clear")
7+
8+
9+
def write_company(company):
10+
file = open(f"{company['name']}.csv", mode="w")
11+
writer = csv.writer(file)
12+
writer.writerow(["place", "title", "time", "pay", "date"])
13+
for job in company["jobs"]:
14+
writer.writerow(list(job.values()))
15+
print(f"Completed....{company['name']}")
16+
17+
18+
alba_url = "http://www.alba.co.kr"
19+
20+
alba_request = requests.get(alba_url)
21+
alba_soup = BeautifulSoup(alba_request.text, "html.parser")
22+
main = alba_soup.find("div", {"id": "MainSuperBrand"})
23+
brands = main.find_all("li", {"class": "impact"})
24+
for brand in brands:
25+
link = brand.find("a", {"class": "goodsBox-info"})
26+
name = brand.find("span", {"class": "company"})
27+
if link and name:
28+
link = link["href"]
29+
name = name.text
30+
if "/" in name :
31+
name = name.replace("/"," ")
32+
company = {'name': name, 'jobs': []}
33+
jobs_request = requests.get(link)
34+
jobs_soup = BeautifulSoup(jobs_request.text, "html.parser")
35+
tbody = jobs_soup.find("div", {"id": "NormalInfo"}).find("tbody")
36+
rows = tbody.find_all("tr", {"class": ""})
37+
for row in rows:
38+
local = row.find("td", {"class": "local"})
39+
if local:
40+
local = local.text
41+
title = row.find("td", {"class": "title"})
42+
if title:
43+
title = title.find("a").find("span", {
44+
"class": "company"
45+
}).text.strip()
46+
47+
time = row.find("td", {"class": "data"})
48+
if time:
49+
time = time.text
50+
pay = row.find("td", {"class": "pay"})
51+
if pay:
52+
pay = pay.text
53+
date = row.find("td", {"class": "regDate"})
54+
if date:
55+
date = date.text
56+
job = {
57+
"place": local,
58+
"title": title,
59+
"time": time,
60+
"pay": pay,
61+
"date": date
62+
}
63+
company['jobs'].append(job)
64+
write_company(company)

0 commit comments

Comments
 (0)