Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #29738 > unrolled thread

Searching the visual appearance of a Web page?

Started byDr J R Stockton <reply1600@merlyn.demon.co.uk.invalid>
First post2016-02-29 23:14 +0000
Last post2016-03-02 00:49 -0800
Articles 6 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Searching the visual appearance of a Web page? Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-02-29 23:14 +0000
    Re: Searching the visual appearance of a Web page? Martin Honnen <mahotrash@yahoo.de> - 2016-03-01 11:39 +0100
      Re: Searching the visual appearance of a Web page? Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-03-03 23:25 +0000
        Re: Searching the visual appearance of a Web page? "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-03-03 16:27 -0800
          Re: Searching the visual appearance of a Web page? Dr J R Stockton <reply1600@merlyn.demon.co.uk.invalid> - 2016-03-05 23:37 +0000
    Re: Searching the visual appearance of a Web page? Bart Van der Donck <bart@nijlen.com> - 2016-03-02 00:49 -0800

#29738 — Searching the visual appearance of a Web page?

FromDr J R Stockton <reply1600@merlyn.demon.co.uk.invalid>
Date2016-02-29 23:14 +0000
SubjectSearching the visual appearance of a Web page?
Message-ID<wW01wWroDN1WFw8z@invalid.uk.co.demon.merlyn.invalid>
I have a reference to the body element of a local Web page, and can
assume that body.onload() has finished.  I also have a RegExp, which has
been defined from the value of an input type=text element.

I want to apply that RegExp to the whole displayed text, all at once or
piecemeal, and get all of the matches.  I have been using the match
method on body.innerText, body.innerHTML, or body.textContent, which was
good enough to do what I wanted, but not ideal.

For example, the text up<br>on in the HTML source must be treated as the
two words "up on" and not the one word "upon".  And, if practical,
"c&acirc;m" should be treated as a three-letter word.

The immediate aim is to use something like /\b[A-Z]{4,}\b/gi to find all
upper-case "word"s of four or more letters, in order to discover most of
the acronyms without too many false positives or negatives, so that a
list of them can be converted into, or used to check, a Glossary.

It can be assumed that the authors of the pages are not trying to delude
this searcher?

How should it best be done, in outline?

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
 Merlyn Web Site <                       > - FAQish topics, acronyms, & links.

[toc] | [next] | [standalone]


#29741

FromMartin Honnen <mahotrash@yahoo.de>
Date2016-03-01 11:39 +0100
Message-ID<nb3rgk$ial$1@news.albasani.net>
In reply to#29738
Dr J R Stockton wrote:
> I have a reference to the body element of a local Web page, and can
> assume that body.onload() has finished.  I also have a RegExp, which has
> been defined from the value of an input type=text element.
>
> I want to apply that RegExp to the whole displayed text, all at once or
> piecemeal, and get all of the matches.  I have been using the match
> method on body.innerText, body.innerHTML, or body.textContent, which was
> good enough to do what I wanted, but not ideal.
>
> For example, the text up<br>on in the HTML source must be treated as the
> two words "up on" and not the one word "upon".  And, if practical,
> "c&acirc;m" should be treated as a three-letter word.

innerText should give you a plain string in which e.g. <br> has been 
converted to a new line character and a character reference to its 
character. The only drawback is that Firefox in its current version 44 
does not support it, but according to 
http://perfectionkills.com/the-poor-misunderstood-innerText/ in Firefox 
45 we will see support. So doing the regular expression search on 
body.innerText seems like the most promising approach. Or why did 
"innerText" not give you the ideal result, unless you needed it with 
Mozilla browsers?

> The immediate aim is to use something like /\b[A-Z]{4,}\b/gi to find all
> upper-case "word"s of four or more letters, in order to discover most of
> the acronyms without too many false positives or negatives, so that a
> list of them can be converted into, or used to check, a Glossary.

> How should it best be done, in outline?

As the article above suggests, an alternative would be to get the text 
of a selection, the article suggests

function getSelectionString(el, win) {
     win = win || window;
     var doc = win.document, sel, range, prevRange, selString;
     if (win.getSelection && doc.createRange) {
         sel = win.getSelection();
         if (sel.rangeCount) {
           prevRange = sel.getRangeAt(0);
         }
         range = doc.createRange();
         range.selectNodeContents(el);
         sel.removeAllRanges();
         sel.addRange(range);
         selString = sel.toString();
         sel.removeAllRanges();
         prevRange && sel.addRange(prevRange);
     }
     else if (doc.body.createTextRange) {
         range = doc.body.createTextRange();
         range.moveToElementText(el);
         range.select();
     }
     return selString;
}

as an implementation, I have tried that in 
https://jsfiddle.net/vb87g1ye/1/, seems to do the "<br>" to new line 
conversion in Mozilla, so perhaps you could check
   if (typeof document.body.innerText != 'undefined')
to work with innerText where supported and use that selection approach 
in Mozilla browsers to get the text.

[toc] | [prev] | [next] | [standalone]


#29790

FromDr J R Stockton <reply1600@merlyn.demon.co.uk.invalid>
Date2016-03-03 23:25 +0000
Message-ID<78AX6LG2fM2WFw29@invalid.uk.co.demon.merlyn.invalid>
In reply to#29741
In comp.lang.javascript message <nb3rgk$ial$1@news.albasani.net>, Tue, 1
Mar 2016 11:39:17, Martin Honnen <mahotrash@yahoo.de> posted:

>Dr J R Stockton wrote:
>> I have a reference to the body element of a local Web page, and can
>> assume that body.onload() has finished.  I also have a RegExp, which has
>> been defined from the value of an input type=text element.
>>
>> I want to apply that RegExp to the whole displayed text, all at once or
>> piecemeal, and get all of the matches.  I have been using the match
>> method on body.innerText, body.innerHTML, or body.textContent, which was
>> good enough to do what I wanted, but not ideal.
>>
>> For example, the text up<br>on in the HTML source must be treated as the
>> two words "up on" and not the one word "upon".  And, if practical,
>> "c&acirc;m" should be treated as a three-letter word.
>
>innerText should give you a plain string in which e.g. <br> has been
>converted to a new line character and a character reference to its
>character. The only drawback is that Firefox in its current version 44
>does not support it, but according to http://perfectionkills.com/the-
>poor-misunderstood-innerText/ in Firefox 45 we will see support. So
>doing the regular expression search on body.innerText seems like the
>most promising approach. Or why did "innerText" not give you the ideal
>result, unless you needed it with Mozilla browsers?

I habitually use the most recent ordinary release of Firefox - Firefox
has "Zoom Text Only" which I consider essential.

I'm using WinXP sp3, and reading files into an iframe, directly from the
disc without any server, WinXP sp3.  Early Chrome was OK, but Chrome 4.0
& later does not do that, it misapplies "Same domain Policy".  Something
fails in Opera 35, with a decent error message; but Opera 12.18 is OK.
IE8 is OK.  Vivaldi gives a message like Opera 35, then falls over dead.

I get the content of the page variously with textContent, innerText, and
innerHTML - and should review those after Firefox 45 appears.

So, as Firefox 45 is due out on Tuesday ...

One use is to search for candidate acronyms for listing across a web
site master - upper-case words of  sensible length.  I should be able to
arrange to maintain a list of acronyms already known (e.g. NATO) and
non-acronyms that look like that (e.g. KABOOM), and then report only the
ones not listed there ...

For amusement - a few years ago, Firefox and Opera would not load page
X.HTM into an IFRAME in page X.HTM, but others would.  The workround, to
read itself rather than a copy of itself, is still in place, and I
wonder whether it is now needed in none, some, or any of the current
browsers.

Thanks.

> ...

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
 Merlyn Web Site <                       > - FAQish topics, acronyms, & links.

[toc] | [prev] | [next] | [standalone]


#29791

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2016-03-03 16:27 -0800
Message-ID<977b2a8d-ed38-4e1e-9509-1bf20f45936f@googlegroups.com>
In reply to#29790
On Thursday, March 3, 2016 at 5:42:47 PM UTC-6, Dr J R Stockton wrote:

> I'm using WinXP sp3, and reading files into an iframe, directly from the
> disc without any server, WinXP sp3.  Early Chrome was OK, but Chrome 4.0
> & later does not do that, it misapplies "Same domain Policy".  Something
> fails in Opera 35, with a decent error message; but Opera 12.18 is OK.
> IE8 is OK.  Vivaldi gives a message like Opera 35, then falls over dead.

You should look at the new standard APIs available:

<https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications>

[toc] | [prev] | [next] | [standalone]


#29827

FromDr J R Stockton <reply1600@merlyn.demon.co.uk.invalid>
Date2016-03-05 23:37 +0000
Message-ID<J3prohDR322WFwRS@invalid.uk.co.demon.merlyn.invalid>
In reply to#29791
In comp.lang.javascript message <977b2a8d-ed38-4e1e-9509-1bf20f45936f@go
oglegroups.com>, Thu, 3 Mar 2016 16:27:38, "Michael Haufe (TNO)"
<tno@thenewobjective.com> posted:

>On Thursday, March 3, 2016 at 5:42:47 PM UTC-6, Dr J R Stockton wrote:
>
>> I'm using WinXP sp3, and reading files into an iframe, directly from the
>> disc without any server, WinXP sp3.  Early Chrome was OK, but Chrome 4.0
>> & later does not do that, it misapplies "Same domain Policy".  Something
>> fails in Opera 35, with a decent error message; but Opera 12.18 is OK.
>> IE8 is OK.  Vivaldi gives a message like Opera 35, then falls over dead.
>
>You should look at the new standard APIs available:
>
><https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications>

Too much new stuff there for me, I fear.  I cannot even see whether what
is on that page, or an associated page, allows me to open a file by code
which uses using a filename string in a way I don't already know.

To be fair on Vivaldi, it does not fall over dead in Windows 7, though
it also does so when updating itself in Win XP.

-- 
 (c) John Stockton, Surrey, UK.  ¬@merlyn.demon.co.uk   Turnpike v6.05   MIME.
 Merlyn Web Site <                       > - FAQish topics, acronyms, & links.

[toc] | [prev] | [next] | [standalone]


#29758

FromBart Van der Donck <bart@nijlen.com>
Date2016-03-02 00:49 -0800
Message-ID<e6264396-7f65-420d-b182-d896a55737a9@googlegroups.com>
In reply to#29738
Dr J R Stockton wrote:

> I have a reference to the body element of a local Web page, and can
> assume that body.onload() has finished.  I also have a RegExp, which has
> been defined from the value of an input type=text element.
> 
> I want to apply that RegExp to the whole displayed text, all at once or
> piecemeal, and get all of the matches.  I have been using the match
> method on body.innerText, body.innerHTML, or body.textContent, which was
> good enough to do what I wanted, but not ideal.
> 
> For example, the text up<br>on in the HTML source must be treated as the
> two words "up on" and not the one word "upon".  And, if practical,
> "c&acirc;m" should be treated as a three-letter word.
> 
> The immediate aim is to use something like /\b[A-Z]{4,}\b/gi to find all
> upper-case "word"s of four or more letters, in order to discover most of
> the acronyms without too many false positives or negatives, so that a
> list of them can be converted into, or used to check, a Glossary.
> 
> It can be assumed that the authors of the pages are not trying to delude
> this searcher?
> 
> How should it best be done, in outline?

Personally, I would probably go for the JQuery approach:

  http://api.jquery.com/text/

-- 
 Bart

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web