|
2 | 2 | from bs4 import BeautifulSoup |
3 | 3 |
|
4 | 4 |
|
5 | | -URL = "https://www.monster.com/jobs/search/?q=Software-Developer\ |
6 | | - &where=Australia" |
| 5 | +URL = "https://realpython.github.io/fake-jobs/" |
7 | 6 | page = requests.get(URL) |
8 | 7 |
|
9 | 8 | soup = BeautifulSoup(page.content, "html.parser") |
10 | 9 | results = soup.find(id="ResultsContainer") |
11 | 10 |
|
12 | 11 | # Look for Python jobs |
13 | | -python_jobs = results.find_all("h2", string=lambda t: "python" in t.lower()) |
14 | | -for p_job in python_jobs: |
15 | | - link = p_job.find("a")["href"] |
16 | | - print(p_job.text.strip()) |
17 | | - print(f"Apply here: {link}\n") |
| 12 | +print("PYTHON JOBS\n==============================\n") |
| 13 | +python_jobs = results.find_all( |
| 14 | + "h2", string=lambda text: "python" in text.lower() |
| 15 | +) |
| 16 | +python_job_elements = [ |
| 17 | + h2_element.parent.parent.parent for h2_element in python_jobs |
| 18 | +] |
18 | 19 |
|
19 | | -# Print out all available jobs from the scraped webpage |
20 | | -job_elems = results.find_all("section", class_="card-content") |
21 | | -for job_elem in job_elems: |
22 | | - title_elem = job_elem.find("h2", class_="title") |
23 | | - company_elem = job_elem.find("div", class_="company") |
24 | | - location_elem = job_elem.find("div", class_="location") |
25 | | - if None in (title_elem, company_elem, location_elem): |
26 | | - continue |
27 | | - print(title_elem.text.strip()) |
28 | | - print(company_elem.text.strip()) |
29 | | - print(location_elem.text.strip()) |
| 20 | +for job_element in python_job_elements: |
| 21 | + title_element = job_element.find("h2", class_="title") |
| 22 | + company_element = job_element.find("h3", class_="company") |
| 23 | + location_element = job_element.find("p", class_="location") |
| 24 | + print(title_element.text.strip()) |
| 25 | + print(company_element.text.strip()) |
| 26 | + print(location_element.text.strip()) |
| 27 | + link_url = job_element.find_all("a")[1]["href"] |
| 28 | + print(f"Apply here: {link_url}\n") |
30 | 29 | print() |
0 commit comments