¿Cómo extraer el código de enlace 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 = "]*?href=[""' ]? (. *?) (? :""|' | ) .[^> ]*? >([\s\S]*?) "
'Extrae todas las expresiones regulares etiquetadas con A, las subcoincidencias se citan entre paréntesis, no. Una es ( . *?) y el segundo es ([\s\S]*?).
Establecer oMatches = .Execute(s)
Si oMatches.Count >= 1 Entonces
Text2 p>Atenuar i como entero
Atenuar sLink como cadena
'Atenuar colLinks como Scripting.Dictionary
'Establecer colLinks = Nuevo Scripting.Dictionary
Atenuar colLinks como objeto
Establezca colLinks = CreateObject("Scripting.Dictionary")
Para cada oMatch en oMatches
sHref = oMatch.SubMatches(0) '(. *?)
sInnerText = oMatch.SubMatches(1) '([\s\S]*?)
sInnerText = RemoveTags(sInnerText) 'Eliminar etiquetas redundantes en una etiqueta (contenido)
sInnerText = Reemplazar(sInnerText, " ", "") 'Eliminar todos los espacios en la etiqueta A (contenido)
sLink = "&.lt;A href=""" & sHref & " "">"" & sInnerText & ""
Si no es colLinks.Exists(sLink) Entonces
colLinks.Text & sLink & p> Finalizar si
Siguiente
Finalizar si
Finalizar con
Establecer oMatches = Nada
Establecer oMatches = Nada
Establecer oRegEx = Nada
Establecer colLinks = Nada
End Sub
'ThisFunction RemoveTags(ByVal html As String)
'Atenuar oRegEx como RegExp
'Establecer oRegEx = Nueva expresión regular
Atenuar oRegEx como objeto
Establecer oRegEx = CreateObject("VBScript . RegExp")
Utilice oRegEx
.Global = True
.IgnoreCase = True
.Pattern = "<[^> ] *>"
RemoveTags = .Replace(html, "")
Finalizar con
Establecer oRegEx = Nada
Finalizar función