Skip to content
Open
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
16 changes: 13 additions & 3 deletions jobspy/glassdoor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,16 @@ def _fetch_jobs_page(
raise GlassdoorException(exc_msg)
res_json = response.json()[0]
if "errors" in res_json:
raise ValueError("Error encountered in API response")
# Only treat errors on the jobListings field as fatal.
# Glassdoor commonly returns non-critical 503s on peripheral
# fields (e.g. jobsPageSeoData) while the job data is intact.
job_errors = [
e for e in res_json["errors"]
if "jobListings" in str(e.get("path", []))
and "jobsPageSeoData" not in str(e.get("path", []))
]
if job_errors:
raise ValueError(f"Error encountered in jobListings API response: {job_errors}")
except (
requests.exceptions.ReadTimeout,
GlassdoorException,
Expand Down Expand Up @@ -151,9 +160,10 @@ def _fetch_jobs_page(

def _get_csrf_token(self):
"""
Fetches csrf token needed for API by visiting a generic page
Fetches csrf token needed for API by visiting the homepage.
Previously used /Job/computer-science-jobs.htm which now returns 404.
"""
res = self.session.get(f"{self.base_url}/Job/computer-science-jobs.htm")
res = self.session.get(f"{self.base_url}/")
pattern = r'"token":\s*"([^"]+)"'
matches = re.findall(pattern, res.text)
token = None
Expand Down