Skip to content

Instantly share code, notes, and snippets.

@Linda-chan
Created July 6, 2021 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Linda-chan/443a8cbbc60fc6f6ed5d6829e5d1e404 to your computer and use it in GitHub Desktop.
Save Linda-chan/443a8cbbc60fc6f6ed5d6829e5d1e404 to your computer and use it in GitHub Desktop.
Option Explicit
DefObj A-Z
'====================================================================
Public Sub Main()
Dim HTML As HTMLDocument
Dim HTML_ As Object
Dim TXT As BStr
Set HTML = New HTMLDocument
Set HTML_ = HTML
TXT = GetSourceFile()
HTML.Clear
HTML_.write TXT
MsgBox HTML.documentElement.innerHTML
FixLinks HTML
MsgBox HTML.documentElement.innerHTML
End Sub
'====================================================================
Private Sub FixLinks(ByRef HTML As HTMLDocument)
Dim Nodes As IHTMLDOMChildrenCollection
Dim Node As IHTMLAnchorElement
Dim TMP As Long
Dim TXT As BStr
Set Nodes = HTML.querySelectorAll("A")
'MsgBox Nodes.Length
For TMP = 0 To Nodes.Length - 1
Set Node = Nodes(TMP)
TXT = Node.href
'MsgBox Len(TXT) & " :: «" & TXT & "»"
TXT = csReReplace(TXT, "^(http)s?(://p\.example\.com)(/)", "$1$2.local$3")
'MsgBox Len(TXT) & " :: «" & TXT & "»"
Node.href = TXT
Next TMP
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment