I'm having a slight issue with a lot of html pages. I'm working for a decent sized company with nearly 15,000 pages in the site.

I've been going through and updating many of the pages with a find and replace function available through Dreamweaver. Recently I've noticed a huge problem.

The last WD of the site must not have known what they were doing when they used a WYSIWYG. So they copied and pasted the design view into the code view to replicate pages.

What occured is the loss of the html tags. On very rare cases the loss of the ending body tag as well. Normally, I can anchor the search to the body tag and insert all the needed information for a header and W3C regulations.

Here is the problem. I am running into a huge amount of files that are missing the ending body tag. I have no commonality to anchor the search to!

I was wondering if there is some way to get dreamweaver to insert ending body and html tags at the end of every document in a search group or some program that can be downloaded free or purchased that can do the same thing in large numbers.

Dani AI

Generated

— with ~15,000 files the safe path is: back everything up, detect which files truly lack closing tags, and then fix them with a low-risk automated pass (not by hand in Dreamweaver). was right that a programmatic approach is the practicable route; below are two practical options: a quick byte-level fixer (minimal formatting change) and a parser-based fixer (more robust but may rewrite markup).

Quick detection (list files missing </body>):

find /path/to/site -type f \( -iname '*.html' -o -iname '*.htm' \) -print0 \
  | xargs -0 grep -L -i '</body>'

Minimal, fast fixer (works on raw bytes; inserts </body> before the last </html> or appends </body></html> if neither exists):

#!/usr/bin/env python3
import os

root = '/path/to/site'
for dirpath, _, files in os.walk(root):
    for f in files:
        if not f.lower().endswith(('.html','.htm')): continue
        p = os.path.join(dirpath, f)
        with open(p, 'rb') as fh: data = fh.read()
        low = data.lower()
        if b'</body>' in low: continue
        pos = low.rfind(b'</html>')
        if pos != -1:
            new = data[:pos] + b'</body>' + data[pos:]
        else:
            new = data + b'\n</body></html>\n'
        if new != data:
            bak = p + '.bak'
            if not os.path.exists(bak): os.rename(p, bak)
            with open(p, 'wb') as fh: fh.write(new)

Parser-based approach (BeautifulSoup) for pages with deeper structural problems — this will reconstruct the DOM and add missing elements, but it can reformat HTML:

from bs4 import BeautifulSoup
import os

root = '/path/to/site'
for dirpath, _, files in os.walk(root):
    for f in files:
        if not f.lower().endswith(('.html','.htm')): continue
        p = os.path.join(dirpath, f)
        with open(p, 'r', encoding='utf-8', errors='replace') as fh: html = fh.read()
        soup = BeautifulSoup(html, 'html.parser')
        new = str(soup)
        if new != html:
            bak = p + '.bak'
            if not os.path.exists(bak): os.rename(p, bak)
            with open(p, 'w', encoding='utf-8') as fh: fh.write(new)

Notes and cautions: always run on a small sample first; preserve backups (or use VCS); watch for server-side includes / fragment files that shouldn’t get full </body></html> appended; check character encodings; validate repaired pages with your validator or a tool like HTML Tidy. The byte-level script is least invasive; the parser fix is safest for malformed DOMs but will change formatting — choose based on test results.

You could write a program that does this. I'm sure the C++, or JAVA guys can help.

Use java.io to open the files
Then search for the </body></html> tags.
if the search is successful move to the next file. else insert the tags at the end of the file, save, and move on to the next file.



Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.