Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
import requests from bs4 import BeautifulSoup import json import re # 1. Definir la URL de la página web URL = "https://www.empleosit.com.ar/search-results-jobs/?searchId=1761583867.6528&action=search&page=1&listings_per_page=100&view=list" def scrape_empleos(url): """ Descarga el contenido de la URL, extrae los datos de los empleos (nombre, descripción, fecha, empresa) y los devuelve en formato JSON. """ # Intentar obtener el contenido de la página try: # Usar headers para simular un navegador y evitar ser bloqueado headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36' } response = requests.get(url, headers=headers, timeout=10) response.raise_for_status() # Lanza una excepción para errores HTTP (4xx o 5xx) html_doc = response.text except requests.exceptions.RequestException as e: return json.dumps({"error": f"Error al acceder a la URL: {e}"}, indent=4, ensure_ascii=False) # 2. Parsear el HTML con BeautifulSoup soup = BeautifulSoup(html_doc, 'html.parser') jobs_data = [] # Identificar el contenedor de cada oferta de empleo # Las ofertas están en divs con clases 'evenrow' u 'oddrow' dentro de 'searchResultsJobs' job_listings = soup.select('.searchResultsJobs > div.evenrow, .searchResultsJobs > div.oddrow') if not job_listings: return json.dumps({"mensaje": "No se encontraron ofertas de empleo con la estructura esperada."}, indent=4, ensure_ascii=False) # 3. Iterar sobre cada oferta y extraer los datos for job in job_listings: # Extraer el Nombre del Puesto (Título) title_tag = job.select_one('.listing-title a') name = title_tag.get_text(strip=True) if title_tag else "N/A" # Extraer la Descripción (resumen) description_tag = job.select_one('.show-brief') if description_tag: # Eliminar la etiqueta
para dejar solo la descripción strong_tag = description_tag.find('strong') if strong_tag: strong_tag.decompose() # Limpiar el texto: quitar espacios extra y el posible ":" inicial description = description_tag.get_text(strip=True).replace(':', '', 1).strip() else: description = "N/A" # Extraer la Fecha # Se encuentra en
date_tag = job.select_one('.captions-field.posted-ico') date = date_tag.get_text(strip=True) if date_tag else "N/A" # Extraer la Empresa # Se encuentra en
dentro de
company_tag = job.select_one('.captions-field.company-ico a') company = company_tag.get_text(strip=True) if company_tag else "N/A" # Agregar los datos al resultado final jobs_data.append({ "nombre": name, "descripcion": description, "fecha": date, "empresa": company }) # 4. Convertir la lista de diccionarios a formato JSON return json.dumps(jobs_data, indent=4, ensure_ascii=False) # Ejecutar el script json_output = scrape_empleos(URL) print(json_output)
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)