Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

web page title

Status
Not open for further replies.

twcman

Programmer
Jun 28, 2001
284
US
Ok, I have a series of .html pages in a dir on my intranet. They have been written by different people using a specific template for the page. I have now been asked to create a table of contents or sitemap for this dir. I can get a list of filenames using cfdir. How can I use cfhttp to find the page title and description in the meta tag? The only dumb questions are the ones that are never asked
 
It would probably be faster to use <CFFILE>, because then you're doing a direct file access instead of requesting the page from the web server. Then, use REReplaceNoCase() to find the contents of the <title> and <meta> tags.

If the directory you wanted to search was &quot;C:\Temp&quot;, for example, you could do this:
Code:
<cfset thisDir = &quot;C:\Temp&quot;>
<cfset files = ArrayNew(1)>
<cfdirectory action=&quot;list&quot; directory=&quot;#thisDir#&quot; name=&quot;qryFileList&quot; filter=&quot;*.cfml&quot;>
<cfloop query=&quot;qryFileList&quot;>
   <cfif NOT ListFind(&quot;.,..&quot;,qryFileList.Name)>
      <cffile action=&quot;read&quot; file=&quot;#thisDir#\#qryFileList.Name#&quot; variable=&quot;thisFile&quot;>
      <cfscript>
         i = ArrayLen(files)+1;
         files[i] = StructNew();
         files[i].name = qryFileList.Name;
         files[i].title = &quot;&quot;;
         files[i].description = &quot;&quot;;
         if(REFindNoCase(&quot;<title>.*</title>&quot;, thisFile))
         {
            files[i].title = REReplaceNoCase(thisFile, &quot;^.*<title>([^>]*)</title>.*$&quot;, &quot;\1&quot;);
         }
         if(REFindNoCase(&quot;<meta name=&quot;&quot;description&quot;&quot; content=&quot;&quot;.*&quot;&quot;&quot;, thisFile))
         {
            files[i].description = REReplaceNoCase(thisFile, &quot;^.*<meta name=&quot;&quot;description&quot;&quot; content=&quot;&quot;([^&quot;&quot;]*)&quot;&quot;.*$&quot;, &quot;\1&quot;);
         }
      </cfscript>
   </cfif>
</cfloop>
This creates an array named &quot;files&quot;, each item of which is a structure describing one file with keys &quot;name&quot;, &quot;title&quot;, and &quot;description&quot;.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top