Cómo extraer direcciones de hipervínculos del código fuente de una página web
Dim s As String
s = Text1.Text
s = Reemplazar(Text1.Text, vbCrLf, "") 'Mover Excepto todos los retornos de carro
'Dim oRegEx As RegExp
'Set oRegEx = New RegExp
'Dim oMatches As MatchCollection
Dim oMatch Como coincidencia
Dim oRegEx como objeto
'Dim oMatches As Match
Dim oRegEx como objeto
Establecer oRegEx = CreateObject("VBScript.RegExp" )
Atenuar oMatches como objeto
Atenuar oMatch como objeto
Con oRegEx
.Global = True 'Coincidencia global
.IgnoreCase = True 'Ignorar mayúsculas y minúsculas
.Pattern = "lt;a[^gt;]*?href=[""' ]? (. *?) (? : "" |' | ).[^gt; ]*? gt; ([\s\S]*?) lt;/agt;"
'Extrae la expresión regular de todas las etiquetas A, contenidas entre paréntesis. donde el primero es (. *?) y el segundo es ([\s\S]*?).
Establecer oMatches = .Execute(s)
Si oMatches.Count gt = 1 Entonces
Text2.Dictionary
'Establecer colLinks = Nuevo Scripting.Dictionary
Atenuar colLinks como objeto
Establecer colLinks = CreateObject("Scripting.Dictionary")
Para cada oMatch en oMatches
sHref = oMatch.SubMatches(0) '(. *?)
sInnerText = oMatch.SubMatches(1) '([\s\S]*?)
sInnerText = RemoveTags(sInnerText) 'Elimina las etiquetas redundantes en la etiqueta A (contenido)
sInnerText = Reemplazar(sInnerText, " ", "") 'Elimina todos los espacios en la etiqueta A (contenido)
p>
sLink = ".lt;A href=""" & sHref & """gt;"" & sInnerText & "lt;/Agt;"
Si no es colLinks.Exists(sLink) Entonces
colLinks.Text & sLink & vbNewLine
Finalizar si
Siguiente
Finalizar si
Terminar con
Establecer oMatches = Nada
Establecer oMatches = Nada
Establecer oRegEx = Nada
Establecer colLinks = Nada
End Sub
'ThisFunction RemoveTags(ByVal html As String)
'Dim oRegEx As RegExp
'Establecer oRegEx = Nueva expresión regular
Dim oRegEx como objeto
Establecer oRegEx = CreateObject("VBScript.RegExp")
Usar oRegEx
.Global = Verdadero
.IgnoreCase = Verdadero
.Pattern = "lt;[^gt;]*gt;"
RemoveTags = .Replace(html, "" )
Terminar con
Establecer oRegEx = Nada
Finalizar función