mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-30 16:31:08 +00:00
2702bf9400
* Enable ruff S113 rule * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
29 lines
933 B
Python
29 lines
933 B
Python
"""
|
|
Scraping jobs given job title and location from indeed website
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Generator
|
|
|
|
import requests
|
|
from bs4 import BeautifulSoup
|
|
|
|
url = "https://www.indeed.co.in/jobs?q=mobile+app+development&l="
|
|
|
|
|
|
def fetch_jobs(location: str = "mumbai") -> Generator[tuple[str, str], None, None]:
|
|
soup = BeautifulSoup(
|
|
requests.get(url + location, timeout=10).content, "html.parser"
|
|
)
|
|
# This attribute finds out all the specifics listed in a job
|
|
for job in soup.find_all("div", attrs={"data-tn-component": "organicJob"}):
|
|
job_title = job.find("a", attrs={"data-tn-element": "jobTitle"}).text.strip()
|
|
company_name = job.find("span", {"class": "company"}).text.strip()
|
|
yield job_title, company_name
|
|
|
|
|
|
if __name__ == "__main__":
|
|
for i, job in enumerate(fetch_jobs("Bangalore"), 1):
|
|
print(f"Job {i:>2} is {job[0]} at {job[1]}")
|