-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindeed.py
More file actions
49 lines (43 loc) · 1.45 KB
/
Copy pathindeed.py
File metadata and controls
49 lines (43 loc) · 1.45 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
import requests
from bs4 import BeautifulSoup
LIMIT = 10
URL = f"https://kr.indeed.com/취업?q=python&l=서울&radius={LIMIT}"
def get_last_page():
result = requests.get(URL)
soup = BeautifulSoup(result.text, "html.parser")
pagination =soup.find("div", {"class": "pagination"})
links = pagination.find_all('a')
pages = []
for link in links[:-1]:
pages.append(int(link.string))
max_page = pages[-1]
return max_page
def extract_job(html):
title = html.find("div", {"class": "title"}).find("a")["title"]
company = html.find("span", {"class" : "company"})
if company:
if company.find("a") != None:
company = str(company.find("a").string)
else:
company = str(company.string)
company = company.strip()
else:
company =None
location = html.find("div", {"class": "recJobLoc"})["data-rc-loc"]
job_id = html["data-jk"]
return {'title': title, 'company': company, 'location':location, "ling": f"https://kr.indeed.com/채용보기?jk={job_id}"}
def extract_jobs(last_page):
jobs = []
for page in range(last_page):
print(f"Scrapping Indeed: Page: {page}")
result = requests.get(f"{URL}&start={page*LIMIT}")
soup = BeautifulSoup(result.text, "html.parser")
results = soup.find_all("div", {"class" : "jobsearch-SerpJobCard"})
for result in results:
job = extract_job(result)
jobs.append(job)
return jobs
def get_jobs():
last_page = get_last_page()
jobs = extract_jobs(last_page)
return jobs