Repository navigation
Expand file tree
/
Copy pathpractise.py
More file actions
56 lines (42 loc) · 2.37 KB
/
Copy pathpractise.py
File metadata and controls
56 lines (42 loc) · 2.37 KB
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
import requests
from bs4 import BeautifulSoup
import csv
def scrape_naukri_job(url):
# Send a GET request to the URL
response = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
# Parse the HTML content
soup = BeautifulSoup(response.content, 'html.parser')
# Extract the required information
job_title = soup.find('h1', class_='jd-header-title').text.strip() if soup.find('h1', class_='jd-header-title') else 'N/A'
company_name = soup.find('a', class_='jd-header-comp-name').text.strip() if soup.find('a', class_='jd-header-comp-name') else 'N/A'
# Salary might not always be available
salary = soup.find('div', class_='salary').text.strip() if soup.find('div', class_='salary') else 'Not specified'
experience = soup.find('div', class_='exp').text.strip() if soup.find('div', class_='exp') else 'N/A'
location = soup.find('div', class_='loc').text.strip() if soup.find('div', class_='loc') else 'N/A'
job_description = soup.find('div', class_='job-desc').text.strip() if soup.find('div', class_='job-desc') else 'N/A'
# Key skills
key_skills = ', '.join([skill.text.strip() for skill in soup.find_all('a', class_='chip clickable')]) if soup.find_all('a', class_='chip clickable') else 'N/A'
# Qualification might be within the job description
qualification = 'Please check job description' # You might need to refine this based on the page structure
return {
'Job Title': job_title,
'Company Name': company_name,
'Job Salary': salary,
'Experience': experience,
'Location': location,
'Job Description': job_description,
'Key Skills': key_skills,
'Qualification': qualification
}
def save_to_csv(data, filename='job_data.csv'):
with open(filename, 'w', newline='', encoding='utf-8') as file:
writer = csv.DictWriter(file, fieldnames=data.keys())
writer.writeheader()
writer.writerow(data)
# URL of the job listing
url = "https://www.naukri.com/job-listings-software-developer-windows-matica-technologies-ag-kolkata-mumbai-new-delhi-hyderabad-pune-chennai-bengaluru-0-to-8-years-070823501186?src=jobsearchDesk&sid=17278426949667072&xp=2&px=1"
# Scrape the job data
job_data = scrape_naukri_job(url)
# Save the data to a CSV file
save_to_csv(job_data)
print("Job data has been scraped and saved to job_data.csv")