[Python] Job Scrapper

 * 노마드코더 Python으로 웹 스크래퍼 만들기 강의를 통해 학습하실 수 있습니다.

 

필요한 모듈
모듈명 사이트 설명
requests https://requests.readthedocs.io/en/master/ Python을 위한 간단한 HTTP 라이브러리
BeautifulSoup https://www.crummy.com/software/BeautifulSoup/bs4/doc/ HTML 및 XML 파일에서 데이터를 꺼내기 위한 Python 라이브러리
csv
https://docs.python.org/3.8/library/csv.html  

 

개발 순서
 1. requests를 이용한 URL 호출 (indeed, statck_of_flow)
 2. 검색 키워드, 페이지 파라미터 찾기
 3. URL 호출로 HTML 전문 가져오기
 4. BeautifulSoup을 이용하여 필요한 데이터의 태그 검색하기
 5. 데이터 리스트 만들기
 6. CSV로 내려 받기

 

1 ~ 2. Request
LIMIT = 50
INDEED_URL = f"https://kr.indeed.com/jobs?limit={LIMIT}"
get_request = requests.get(f"{INDEED_URL}&q={keyword}")

 

3. HTML 전문 가져오기
html_parse = bs(get_request.text, 'html.parser')

 

4 ~ 5. 필요한 데이터 태그 검색하기

 - 페이지

 

# 페이지 관련 태그를 가져와 필요한 태그를 모두 조회
pages = html_parse.find("div", {"class": "pagination"}).find_all('a')
page_list = []
# pagination 리스트의 마지막이 next라서 제외 한 뒤에 마지막 page를 가져옴
for page in pages[:-1]:
page_value = int(page.find('span').string)
page_list.append(page_value)
max_page = page_list[-1]
view raw last_page hosted with ❤ by GitHub

 

 - job 관련 데이터

 

# 페이지, 키워드 파라미터를 포함하여 HTML 전문 호출 후 필요한 데이터만 추출
get_request = requests.get(f"{INDEED_URL}&q={word}&start={page*LIMIT}")
html_parse = bs(get_request.text, 'html.parser') # HTML 파싱
results = html_parse.find_all("div", {"class": "jobsearch-SerpJobCard"})
for html in results:
h2_title = html.find("h2", {"class": "title"})
title = h2_title.find("a")["title"]
span_company = html.find("span", {"class": "company"})
a_company = span_company.find("a")
company = ""
if a_company is not None:
company = str(a_company.string)
else:
company = str(span_company.string)
company = company.strip()
location = html.find("div", {"class": "recJobLoc"})["data-rc-loc"]
job_id = html["data-jk"]
job = {
"title": title,
"company": company,
"location": location,
"link": f"https://kr.indeed.com/viewjob?jk={job_id}"
}
jobs.append(job)
view raw extract_job hosted with ❤ by GitHub

 

6. CSV 파일로 내려 받기

 

file = open("jobs.csv", mode="w")
write = csv.writer(file)
write.writerow([*jobs[0].keys()])
for job in jobs:
write.writerow([*job.values()])
view raw csv_file hosted with ❤ by GitHub

 

Flask를 이용한 Job List Data Crawling

 * 간단한 데이터는 Flask를 이용해 CSV파일로 만들고, 보다 큰 데이터는 Django를 이용해 프로젝트 작성 할 것

'Edu > Nomad Coders' 카테고리의 다른 글

[AWS - Django] 배포하기  (0) 2020.04.09
[Airbnb] 정리  (0) 2020.03.14

+ Recent posts