vbScript help - looking for links inside a file

I am working on a vbScript that should crawl all the external links values from file.... The goal of the app is to scan a file and extract all the references to https://

The content of the file is attached here, the vbScript should create a HTML file with all the links it founded in the target file...

]]></value></Data><Data name="Goto_Link"><value><![CDATA[https://methodology.AFUEGO.com/core_custom/#base.development/tasks/Manage%20Project%20Resources_D225EF0A.html]]></value></Data><Data name="Picture"><value><![CDATA[http://methoddev.AFUEGO.com/accelerator/custom_portal/slides/task1025.gif]]></value></Data><Data name="Sample"><value><![CDATA[<ul><li><a href=https://tsamr.AFUEGO.com/Sites/delivlibrary/Deliverable%20Repository/Forms/Portal%20Development.aspx?FilterField1=Deliverable%5fx0020%5fID&FilterValue1=PM246>PM246 Team Charter Samples<li><a href=https://tsamr.AFUEGO.com/Sites/delivlibrary/Deliverable%20Repository/Forms/Portal%20Development.aspx?FilterField1=Deliverable%5fx0020%5fID&FilterValue1=PM262>PM262 Roles and Responsibilities Samples</a><li><a href=https://tsamr.AFUEGO.com/Sites/delivlibrary/Deliverable%20Repository/Forms/Portal%20Development.aspx?FilterField1=Deliverable%5fx0020%5fID&FilterValue1=PM266>PM266 Training Needs Matrix Samples</a></ul>

Would this be possible, based on the format of my file.
LVL 8
a0k0a7Asked:
Who is Participating?
 
sirbountyCommented:
If I read you right...try this:
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOut : Set objOut = objFSO.CreateTextFile("C:\Links.html")
 
strData = LCase(objFSO.OpenTextFile("C:\testfile.html").ReadAll)
 
DataToFind = "https:"
iStart = 1
iEnd = 1
x = 1
 
objOut.WriteLine "<html><body>"
 
Do 
  iStart = Instr(iEnd, strData, DataToFind)
  If iStart = 0 Then Exit Do
  iEnd = Instr(Instr(iEnd, strData, DataToFind), strData, ">")
  objOut.WriteLine "<a href=" & mid(strData,iStart, iEnd + 1 - iStart) & x & "</a>"
  x = x +1
Loop until iStart = 0
 
objOut.WriteLine "</body></html>" 
objOut.Close

Open in new window

0
 
sirbountyCommented:
This is what the following script produces from your example...

https://methodology.afuego.com/core_custom/#base.development/tasks/manage%20project%20resources_d225ef0a.html]]
https://tsamr.afuego.com/sites/delivlibrary/deliverable%20repository/forms/portal%20development.aspx?filterfield1=deliverable%5fx0020%5fid&filtervalue1=pm246
https://tsamr.afuego.com/sites/delivlibrary/deliverable%20repository/forms/portal%20development.aspx?filterfield1=deliverable%5fx0020%5fid&filtervalue1=pm262
https://tsamr.afuego.com/sites/delivlibrary/deliverable%20repository/forms/portal%20development.aspx?filterfield1=deliverable%5fx0020%5fid&filtervalue1=pm266


Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objOut : Set objOut = objFSO.CreateTextFile("C:\Links.txt")
 
strData = LCase(objFSO.OpenTextFile("C:\testfile.html").ReadAll)
 
DataToFind = "https:"
iStart = 1
iEnd = 1
 
Do 
  iStart = Instr(iEnd, strData, DataToFind)
  If iStart = 0 Then Exit Do
  iEnd = Instr(Instr(iEnd, strData, DataToFind), strData, ">")
  objOut.WriteLine mid(strData,iStart, iEnd - iStart)
Loop until iStart = 0
 
objOut.Close

Open in new window

0
 
a0k0a7Author Commented:
Thank you very much Chief.... works like a charm...

how I could make that the URLs are inside of a href tag, so when I open the output file I can click to check my links.
0
 
a0k0a7Author Commented:
thank you Bawse =D
0
 
sirbountyCommented:
You bet - thanx for the grade. :^)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.