Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
Extract URLs from HTML and JS source, with multiple on a line

I'd like to list all the domains our source code refers to, allowing the limitation of finding only those that are statically referenced and begin with https?://. For example, I've tried the following:

find -s [^.]* -print0 | xargs -0 sed -En 's/.*https?:\/\/([a-z0-9\-\.\_]+).*/\1/p' | sort | uniq

The bug is, when there's more than one domain on a single line, only one will be returned. Can this be remedied with simple shell tools, ie without fully parsing the HTML?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The regular expression .* is greedy, so putting it at both the beginning and end of your regex will discard any other URLs that are on the same line.

Standard grep is unable to print capture groups like ([a-z0-9-._]+), but if you have perl, replace this:

sed -En 's/.*https?:\/\/([a-z0-9\-\.\_]+).*/\1/p'

with this:

perl -nle 'print $1 while m{https?://([a-z0-9-._]+)}g'
  • https?://([a-z0-9-._]+) is our new regular expression that matches only what we're looking for, keeping each line intact.
  • while m{...}g iterates through each match of the regex.
  • print $1 displays the first capture of our regex ([a-z0-9-._]+)

Your final command will be:

find -s [^.]* -print0 | xargs -0 perl -nle 'print $1 while m{https?://([a-z0-9-._]+)}g' | sort | uniq
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda