We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

vbScript help - looking for links inside a file

a0k0a7
a0k0a7 asked
on
Medium Priority
269 Views
Last Modified: 2012-05-06
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.
Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2007

Commented:
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

Author

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.
CERTIFIED EXPERT
Top Expert 2007
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
thank you Bawse =D
CERTIFIED EXPERT
Top Expert 2007

Commented:
You bet - thanx for the grade. :^)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.