호그와트

대나무숲 1 돌파

영웅*^%&$ 2022. 2. 28. 11:59
728x90

import requests

from bs4 import BeautifulSoup

LIMIT = 50

URL = "http://www.indeed.com/jobs?q=python&limit={LIMIT}"

def extract_indeed_pages():

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("h2", {

"class": "jobTitle"

}).find("span", title=True).text

company = html.find("span", {"class": "companyName"})

company_anchor = company.find("a")

if company:

company_anchor = company.find("a")

if company_anchor is not None:

company = str(company_anchor.string)

else:

company = str(company.string)

location = html.find("div", {"class": "companyLocation"}).string

job_id = html["data-jk"]

return {

"title": title,

"company": company,

"location": location,

"link": f"https://www.indeed.com/viewjob?jk={job_id}&tk=1fpkb65caocag800&from=serp&vjs=3"

}

def extract_jobs(last_page):

jobs = []

for page in range(last_page):

result = requests.get(f"{URL}&start={page*LIMIT}")

soup = BeautifulSoup(result.text, "html.parser")

results = soup.find_all("a", {"class": "fs-unmask"})

for result in results:

job = extract_job(result)

jobs.append(job)

return jobs

///////////////////////indeed.py ///////////////////////

from indeed import extract_indeed_pages, extract_job, extract_jobs

last_indeed_page = extract_indeed_pages()

indeed_jobs = extract_jobs(last_indeed_page)

print(indeed_jobs)

/////////////////main.py//////////////////

728x90

'호그와트' 카테고리의 다른 글

드림핵 spring view  (0) 2022.04.06
드림핵 sint  (0) 2022.03.01
Dreamhack login-1  (0) 2022.02.24
extract company  (0) 2022.02.24
extract title jobs  (0) 2022.02.24