Herramientas de Análisis Web
Herramientas de Análisis Web
htmlq
Extractor de contenido HTML usando selectores CSS (como jq pero para HTML).
Instalación
# Arch Linux
sudo pacman -S htmlq
# Cargo
cargo install htmlq
Uso Básico
# Extraer todos los títulos
htmlq -t 'h1' archivo.html
# Extraer enlaces
htmlq -t 'a' -o url archivo.html
# Extraer contenido de div específico
htmlq '#contenido' pagina.html
# Multiple selectores
htmlq 'title, h1, h2' pagina.html
Opciones
| Opción | Descripción |
|---|---|
-t |
Selector CSS |
-o |
Output attribute |
-w |
Wrapping HTML |
--indent |
Identación |
Ejemplos
# Extraer todos los enlaces de una página
curl -s https://ejemplo.com | htmlq -t 'a' -o href
# Extraer imágenes
curl -s https://ejemplo.com | htmlq 'img' -o src
#清洗 datos de tablas
htmlq 'table td' pagina.html
html2text
Convierte HTML a texto plano legible.
Instalación
# Arch Linux
sudo pacman -S html2text
# pip
pip install html2text
Uso Básico
# Convertir a texto
html2text archivo.html
# Desde stdin
curl -s https://ejemplo.com | html2text
# Ancho de línea
html2text -w 100 archivo.html
# Ignorar enlaces
html2text -b 0 archivo.html
Opciones
| Opción | Descripción |
|---|---|
-w |
Ancho de línea |
-b |
Ancho de sangría |
--escape |
Escapar caracteres |
Pipeline de Uso
# Extraer y limpiar contenido web
curl -s https://target.com | htmlq 'article' | html2text
# Extraer emails de una página
curl -s target.com | htmlq -t 'a' -o href | grep -oE 'mailto:[^ ]+'