Skip to content

Commit 6e8576f

Browse files
authored
fix(naukri): prevent str.find error by normalizing input and parsing before Markdown (#300)
1 parent 5188800 commit 6e8576f

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

jobspy/naukri/__init__.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,15 @@ def _process_job(
164164
date_posted = self._parse_date(job.get("footerPlaceholderLabel"), job.get("createdDate"))
165165

166166
job_url = f"https://www.naukri.com{job.get('jdURL', f'/job/{job_id}')}"
167-
description = job.get("jobDescription") if full_descr else None
167+
raw_description = job.get("jobDescription") if full_descr else None
168+
169+
job_type = parse_job_type(raw_description) if raw_description else None
170+
company_industry = parse_company_industry(raw_description) if raw_description else None
171+
172+
description = raw_description
168173
if description and self.scraper_input.description_format == DescriptionFormat.MARKDOWN:
169174
description = markdown_converter(description)
170175

171-
job_type = parse_job_type(description) if description else None
172-
company_industry = parse_company_industry(description) if description else None
173176
is_remote = is_job_remote(title, description or "", location)
174177
company_logo = job.get("logoPathV3") or job.get("logoPath")
175178

jobspy/naukri/util.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@
55
from jobspy.util import get_enum_from_job_type
66

77

8-
def parse_job_type(soup: BeautifulSoup) -> list[JobType] | None:
8+
def parse_job_type(soup: BeautifulSoup |str) -> list[JobType] | None:
99
"""
1010
Gets the job type from the job page
1111
"""
12+
if isinstance(soup, str):
13+
soup = BeautifulSoup(soup, "html.parser")
1214
job_type_tag = soup.find("span", class_="job-type")
1315
if job_type_tag:
1416
job_type_str = job_type_tag.get_text(strip=True).lower().replace("-", "")
1517
return [get_enum_from_job_type(job_type_str)] if job_type_str else None
1618
return None
1719

1820

19-
def parse_company_industry(soup: BeautifulSoup) -> str | None:
21+
def parse_company_industry(soup: BeautifulSoup | str) -> str | None:
2022
"""
2123
Gets the company industry from the job page
2224
"""
25+
if isinstance(soup, str):
26+
soup = BeautifulSoup(soup, "html.parser")
2327
industry_tag = soup.find("span", class_="industry")
2428
return industry_tag.get_text(strip=True) if industry_tag else None
2529

0 commit comments

Comments
 (0)