-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackoverflow.py
More file actions
58 lines (41 loc) ยท 1.95 KB
/
stackoverflow.py
File metadata and controls
58 lines (41 loc) ยท 1.95 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
import requests
from bs4 import BeautifulSoup
URL = "https://stackoverflow.com/jobs?q=python"
# ๋ง์ง๋ง ํ์ด์ง ๊ฐ์ ธ์ค๊ธฐ
def get_last_page():
result = requests.get(URL)
soup = BeautifulSoup(result.text, "html.parser")
pages = soup.find("div", {"class":"s-pagination"}).find_all('a')
last_page = pages[-2].get_text(strip=True)
return int(last_page)
# ์ฑ์ฉ ๊ณต๊ณ ์์ ์ฑ์ฉ ์ง๋ฌด์ ํ์ฌ๋ช
, ํ์ฌ ์์น, ์ง์ ๋งํฌ ๊ฐ์ ธ์ค๋ ํจ์
def extract_job(html):
title = html.find("h2", {"class":"mb4"}).find('a')["title"]
# company = html.find("h3").find('span').get_text(strip=True)
# location = html.find("h3").find('span', {"class":"fc-black-500"}).get_text(strip=True)
# ์์์ฒ๋ผ ๊ทธ๋ฅ ๋ฐ๋ก ์ถ์ถํด๋ ๋๊ณ ,
# find_all('span') ํ๋๋ฐ, span ์์ span์ด ๋ ์๋ ๊ฒฝ์ฐ๋ ํ์ span์ ํ์์์ผ๋ฏ๋ก firstlevel span๋ง ๊ฐ์ ธ์ค์ -> recursive=False
# company_row = html.find("h3", {"class":"fc-black-700"}).find_all("span", recursive=False)
# company = company_row[0]
# location = company_row[1]
company, location = html.find("h3", {"class":"fc-black-700"}).find_all("span", recursive=False)
company = company.get_text(strip=True)
location = location.get_text(strip=True)
job_id = html["data-jobid"]
return {'title':title, 'company':company, 'location':location, "apply_link":f"https://stackoverflow.com/jobs/{job_id}"}
# ์กด์ฌํ๋ ํ์ด์ง์ url ์์ฑ ํ requestํ์ฌ ๊ฐ ํ์ด์ง์ ์ฑ์ฉ ๊ณต๊ณ ๋ฅผ ๊ฐ์ ธ์ค๋ ํจ์
def extract_jobs(last_page):
jobs = []
for page in range(last_page):
result = requests.get(f"{URL}&pg={page+1}")
soup = BeautifulSoup(result.text, "html.parser")
results = soup.find_all("div", {"class":"-job"})
#print(f"--------{page+1}----------")
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