AkkixDev
AkkixDev

Reputation: 450

Extract Page Title using vbscript (Offline Html pages)

So i have a lot of educational html pages and i need to extract title from each page , I was not sure it should be done this way , Anyways i gave it a try..

Function gettitle(strfile)
Set text = fso.OpenTextFile(strfile ,1)
title = ""
read = text.ReadAll
text.Close
WScript.Echo read                      'Everything fine till here
strdata = InStr("<title>" ,read,1)
If strdata <> 0 Then
 intstart = strdata + 7                ' "<title>" which is 7 characters long)
 strtext = Mid(text,intstart,250)
 For i = 1 To Len(strtext)
   If Mid(strtext,i,1)= "<" Then        'Before next "<" tag , title gets extracted 
      Exit For
   Else
      title = title & Mid(strtext,i,1)
   End If
 Next
End if
WScript.Echo title                 'I get Null value here
End Function

I get a null value for title . Help would be appreciated

Upvotes: 0

Views: 472

Answers (1)

AkkixDev
AkkixDev

Reputation: 450

I corrected it . So with this script , Titles from html pages can be extracted .

Function gettitle(strfile)
'On Error Resume next
Set text = fso.OpenTextFile(strfile ,1)
title = ""
read = text.Readall
strdata = InStr(read,"<title>")
If strdata <> 0 Then
 intstart = strdata + 7
 strtext = Mid(read,intstart,250)
 For i = 1 To Len(strtext)
   If Mid(strtext,i,1)= "<" Then
      Exit For
   Else
      title = title & Mid(strtext,i,1)
   End If
 Next
End if
WScript.Echo title
End Function

Upvotes: 1

Related Questions