Skip to content

Commit

Permalink
Merge pull request #1010 from msabry1/bayt-feature
Browse files Browse the repository at this point in the history
Bayt feature Added
  • Loading branch information
nikhil25803 authored May 19, 2024
2 parents e25dc52 + 6bd81be commit 1d8f12f
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
18 changes: 16 additions & 2 deletions dev-documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,7 @@ geeksforgeeks = Geeksforgeeks(user="username")
## Wuzzuf

```python
from scrap_up import wuzzuf
from scrape_up import wuzzuf
jobs = wuzzuf.Jobs()
```

Expand Down Expand Up @@ -1750,7 +1750,7 @@ result = steam.ScrapeGames(n0Games=5, tags=["Discounts", "F2P"])
## Lichess

```python
from scrape-up import lichess
from scrape_up import lichess
lichess_games = lichess.LichessGames(username)
start_page = 1
end_page = 4
Expand Down Expand Up @@ -1851,3 +1851,17 @@ trek=Indiantrekking("hidden-lakes-of-kashmir")
| `outline_day_to_day_itinerary` | returns the ouline of the day to day itinerary |

---

## Bayt

```python
from scrape_up import bayt
jobs = bayt.Jobs()
jobs.fetch_jobs(query="software engineer",page=1)
```

The `Jobs` class provides methods fetching job listings:

| Methods | Details |
| --------------- | ----------------------------------------------------------------- |
| `.fetch_jobs()` | Fetch job listings from the website across specified single page. |
3 changes: 3 additions & 0 deletions src/scrape_up/bayt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .bayt import Jobs

__all__ = ["Jobs"]
90 changes: 90 additions & 0 deletions src/scrape_up/bayt/bayt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import sys
import requests
from bs4 import BeautifulSoup


class Jobs:
"""
Create an instance of the class `Jobs`
```python
scraper = Jobs()
jobs_data = scraper.fetch_jobs(query, page)
```
| Methods | Details |
| ----------------------------- | -------------------------------------------------------------------------- |
| `.fetch_jobs(query, page)` | Fetch job listings data from Bayt.com based on the given query and page. |
"""

def __init__(self):
self.base_url = "https://www.bayt.com"

def fetch_jobs(self, query, page=1):
"""
Fetch job listings data from Bayt.com based on the given query and page.
Parameters:
- `query`: The job search query.
- `page` : The page number of the search results (default: 1).
Example:
```python
scraper = Jobs()
jobs_data = scraper.fetch_jobs("software developer", page=1)
```
"""
try:
url = f"{self.base_url}/en/international/jobs/{query}-jobs/?page={page}"
response = requests.get(url)

response.raise_for_status()

soup = BeautifulSoup(response.text, "html.parser")
job_listings = soup.find_all("li", class_="has-pointer-d")

jobs = []
for job in job_listings:
job_info = self.__extract_job_info(job)
if job_info:
jobs.append(job_info)
sys.stdout.reconfigure(encoding="utf-8")
return jobs
except Exception:
return None

def __extract_job_info(self, job):
"""
Extract job information from a single job listing.
"""
job_general_information = job.find("h2", class_="jb-title")
if not job_general_information:
return None

job_title = self.__extract_job_title(job_general_information)
job_url = self.__extract_job_url(job_general_information)
company_name = self.__extract_company_name(job)
job_location = self.__extract_job_location(job)

return {
"title": job_title,
"company": company_name,
"location": job_location,
"url": job_url,
}

def __extract_job_title(self, job_general_information):
return job_general_information.text.strip()

def __extract_job_url(self, job_general_information):
return self.base_url + job_general_information.a["href"].strip()

def __extract_company_name(self, job):
company_name = job.find("b", class_="jb-company")
if company_name:
return company_name.text.strip()
return None

def __extract_job_location(self, job):
job_location = job.find("span", class_="jb-loc")
if job_location:
return job_location.text.strip()
return None
1 change: 0 additions & 1 deletion src/scrape_up/codeforces/contests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ def get_contests(self):
contest_list = []

try:

upcoming_contests = soup.find("div", {"class": "datatable"}).find_all("tr")
for contest in upcoming_contests:
columns = contest.find_all("td")
Expand Down

0 comments on commit 1d8f12f

Please sign in to comment.