1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| def parse_job_data_from_json(response_data, output_json_file, output_markdown_file): """ Parse job data from a list of responses and extract job listings using BeautifulSoup. Save results to both a JSON file and a Markdown file.
Args: response_data (list): List of dictionaries containing the response data. output_json_file (str): Path to save the parsed job data in JSON format. output_markdown_file (str): Path to save the parsed job data in Markdown format. """ try: job_data = [] markdown_content = []
for request in response_data: counter = request.get("counter", "unknown") response_content = request.get("response_content", "")
soup = BeautifulSoup(response_content, 'html.parser')
job_listings = soup.find_all('li', class_='job-listing')
for job in job_listings: job_title = job.find('a', class_='jobList-title zip-backfill-link') job_description = job.find('div', class_='jobList-description') salary = job.find('div', class_='jobList-salary')
job_info = { 'title': job_title.text.strip() if job_title else 'N/A', 'href': job_title['href'] if job_title else 'N/A', 'description': job_description.text.strip() if job_description else 'N/A', 'salary': salary.text.strip() if salary else 'N/A', 'page': counter } job_data.append(job_info)
markdown_entry = f""" ### Job Title: {job_info['title']} - **Link**: [{job_info['title']}]({job_info['href']}) - **Description**: {job_info['description']} - **Salary**: {job_info['salary']} - **Page**: {job_info['page']} """ markdown_content.append(markdown_entry.strip())
with open(output_json_file, 'w', encoding='utf-8') as f: json.dump(job_data, f, ensure_ascii=False, indent=4)
print(f"Job data successfully parsed and saved to {output_json_file}")
with open(output_markdown_file, 'w', encoding='utf-8') as f: f.write("\n\n".join(markdown_content))
print(f"Job data successfully saved to {output_markdown_file}")
except Exception as e: print(f"Error processing file: {e}")
|