473,387 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Extracting text (cross platform)

Is there a standard way to extract text from a web page, without using
innertext/innerhtml?

It's an academic exercise, and we've been advised that we can't use
Internet Explorer DOM extensions that are not part of the W3C DOM.

Thanks,

Debbie

Jul 16 '06 #1
2 1551


Debbie wrote:
Is there a standard way to extract text from a web page, without using
innertext/innerhtml?

It's an academic exercise, and we've been advised that we can't use
Internet Explorer DOM extensions that are not part of the W3C DOM.
Well then use the W3C DOM, text will sit in text nodes as leaf nodes of
the DOM tree and each text node has a property named nodeValue that will
give you the text in the text node. You could also use the data property
for that.
If you want the text in an element then you will either have to go
through the child nodes and concatenate the text of the child nodes
(where you might have to recursively go down the tree until you have the
text nodes) or depending on your needs and requirements you can use the
W3C DOM Level 3 property named textContent which Mozilla has been
supporting for quite some time and which at least Opera supports too now.
Then there is the W3C DOM Level 2 Range API that also allows you to get
the text in a range so you could position the range on an element node
and call toString on the range e.g.
var range = document.createRange();
range.selectNodeContents(someNode);
var text = range.toString();
Mozilla and Opera 8 and later support the Range API.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 16 '06 #2
Thank you, Martin, that does just what I was looking for.

Regards,

Debbie

Jul 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Christopher Subich | last post by:
As a hobby project, I'm writing a MUD client -- this scratches an itch, and is also a good excuse to become familiar with the Python language. I have a conceptual handle on most of the...
7
by: Web Master | last post by:
Are there any good websites or books that deal with cross platform XML? I'd like to target Internet Explorer/Netscape Navigator 5 or later, as well as Opera, possibly konqueror on Linux as well. ...
0
by: demibee | last post by:
Thought this might be of interest to some out there... For those who've never encountered it, it's a free, open-source, cross-platform GUI library (Windows/Mac/Linux). Forte's Agent 2.0 will be...
29
by: runningdog | last post by:
Hi, I would like to be able to embed a newline in a text string. Is there any convienent notation to do this TIA Steve
6
by: saleemahmad70 | last post by:
Hi.. I am stuck with a problem where I need to extract some information from a File in C++.e.g File size,date of creation, Location on the Disk etc. I haven't been able to find any particular...
7
by: Charles | last post by:
I'd like to develop a simple cross-platform application in C++. I'd like it to run in Windows, OS X, PC-BSD and Linux. From my research, it seems I should use Qt or Gtk as a graphical library. Do...
5
by: Michael Reichenbach | last post by:
After working with script languages, notepad(++) and co. and several other ide`s I found something which really improved my productivity (Visual Studio 2005). It`s imho better then dev-cpp... I...
1
by: Vinod Sadanandan | last post by:
Cross Platform Migration An Unproblematic Approach (Windows-UNIX ) Oracle 10\11g The principal restriction on cross-platform transportable database is that the source and destination platform...
42
by: =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?= | last post by:
I'm currently writing a program and I've got in mind to keep it as portable as possible. In particular I want it to run on Linux and Windows, but I'm also keeping an open mind to any machine that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.