Skip to content

issue#270: glassdoor 403 response by rotating user-agent and updating… #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion jobspy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def scrape_jobs(
hours_old: int = None,
enforce_annual_salary: bool = False,
verbose: int = 0,
user_agent: str = None,
**kwargs,
) -> pd.DataFrame:
"""
Expand Down Expand Up @@ -98,7 +99,7 @@ def get_site_type():

def scrape_site(site: Site) -> Tuple[str, JobResponse]:
scraper_class = SCRAPER_MAPPING[site]
scraper = scraper_class(proxies=proxies, ca_cert=ca_cert)
scraper = scraper_class(proxies=proxies, ca_cert=ca_cert, user_agent=user_agent)
scraped_data: JobResponse = scraper.scrape(scraper_input)
cap_name = site.value.capitalize()
site_name = "ZipRecruiter" if cap_name == "Zip_recruiter" else cap_name
Expand Down
2 changes: 1 addition & 1 deletion jobspy/bayt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class BaytScraper(Scraper):
band_delay = 3

def __init__(
self, proxies: list[str] | str | None = None, ca_cert: str | None = None
self, proxies: list[str] | str | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
super().__init__(Site.BAYT, proxies=proxies, ca_cert=ca_cert)
self.scraper_input = None
Expand Down
6 changes: 4 additions & 2 deletions jobspy/glassdoor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@

class Glassdoor(Scraper):
def __init__(
self, proxies: list[str] | str | None = None, ca_cert: str | None = None
self, proxies: list[str] | str | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
"""
Initializes GlassdoorScraper with the Glassdoor job search url
"""
site = Site(Site.GLASSDOOR)
super().__init__(site, proxies=proxies, ca_cert=ca_cert)
super().__init__(site, proxies=proxies, ca_cert=ca_cert, user_agent=user_agent)

self.base_url = None
self.country = None
Expand All @@ -65,6 +65,8 @@ def scrape(self, scraper_input: ScraperInput) -> JobResponse:
)
token = self._get_csrf_token()
headers["gd-csrf-token"] = token if token else fallback_token
if self.user_agent:
headers["user-agent"] = self.user_agent
self.session.headers.update(headers)

location_id, location_type = self._get_location(
Expand Down
2 changes: 1 addition & 1 deletion jobspy/google/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class Google(Scraper):
def __init__(
self, proxies: list[str] | str | None = None, ca_cert: str | None = None
self, proxies: list[str] | str | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
"""
Initializes Google Scraper with the Goodle jobs search url
Expand Down
2 changes: 1 addition & 1 deletion jobspy/indeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

class Indeed(Scraper):
def __init__(
self, proxies: list[str] | str | None = None, ca_cert: str | None = None
self, proxies: list[str] | str | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
"""
Initializes IndeedScraper with the Indeed API url
Expand Down
2 changes: 1 addition & 1 deletion jobspy/linkedin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class LinkedIn(Scraper):
jobs_per_page = 25

def __init__(
self, proxies: list[str] | str | None = None, ca_cert: str | None = None
self, proxies: list[str] | str | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
"""
Initializes LinkedInScraper with the LinkedIn job search url
Expand Down
3 changes: 2 additions & 1 deletion jobspy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,12 @@ class ScraperInput(BaseModel):

class Scraper(ABC):
def __init__(
self, site: Site, proxies: list[str] | None = None, ca_cert: str | None = None
self, site: Site, proxies: list[str] | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
self.site = site
self.proxies = proxies
self.ca_cert = ca_cert
self.user_agent = user_agent

@abstractmethod
def scrape(self, scraper_input: ScraperInput) -> JobResponse: ...
2 changes: 1 addition & 1 deletion jobspy/naukri/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Naukri(Scraper):
jobs_per_page = 20

def __init__(
self, proxies: list[str] | str | None = None, ca_cert: str | None = None
self, proxies: list[str] | str | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
"""
Initializes NaukriScraper with the Naukri API URL
Expand Down
2 changes: 1 addition & 1 deletion jobspy/ziprecruiter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ZipRecruiter(Scraper):
api_url = "https://api.ziprecruiter.com"

def __init__(
self, proxies: list[str] | str | None = None, ca_cert: str | None = None
self, proxies: list[str] | str | None = None, ca_cert: str | None = None, user_agent: str | None = None
):
"""
Initializes ZipRecruiterScraper with the ZipRecruiter job search url
Expand Down