File size: 1,805 Bytes
4b926ea |
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 |
import requests
from bs4 import BeautifulSoup
import pandas as pd
import gradio as gr
def scrape_jobs(link):
# Send a GET request to the carrier website
response = requests.get(link)
# Parse the HTML content using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')
# Find all the job listings on the page
job_elements = soup.find_all('div', class_='job-listing')
jobs = []
for job_element in job_elements:
# Extract relevant information from each job listing
job_title = job_element.find('h2', class_='job-title').text.strip()
job_location = job_element.find('span', class_='job-location').text.strip()
job_description = job_element.find('div', class_='job-description').text.strip()
# Store the job information in a dictionary
job = {
'Title': job_title,
'Location': job_location,
'Description': job_description
}
jobs.append(job)
return jobs
def export_to_excel(jobs, filename):
# Create a DataFrame from the job data
df = pd.DataFrame(jobs)
# Save the DataFrame to an Excel file
df.to_excel(filename, index=False)
def job_listing_scraper(link):
job_listings = scrape_jobs(link)
output_file = "job_listings.xlsx"
export_to_excel(job_listings, output_file)
return f"Job listings scraped successfully! Saved to {output_file}"
# Define the Gradio interface
interface = gr.Interface(
fn=job_listing_scraper,
inputs="text",
outputs="text",
title="Job Listing Scraper",
description="Enter the link to the carrier website and click 'Submit' to scrape job listings and save them to an Excel file.",
examples=[["https://example.com/carrier"]],
)
# Run the Gradio interface
interface.launch() |