?
Solved

vbScript help - looking for links inside a file

Posted on 2009-02-17
5
Medium Priority
?
260 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.
0
Comment
Question by:a0k0a7
  • 3
  • 2
5 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 23664818
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
 
LVL 8

Author Comment

by:a0k0a7
ID: 23665034
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
 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 23665098
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
 
LVL 8

Author Closing Comment

by:a0k0a7
ID: 31548029
thank you Bawse =D
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 23665573
You bet - thanx for the grade. :^)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question