How to calculate the number of words in any book by algorithm?

The first kind: all books will be marked, most of them are on the back of the book and a few are on the cover of the book.

The second type: the number of words in each line of a book multiplied by the number of lines and then multiplied by the page number.