473,795 Members | 3,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

finding text on webpage

How would I access the source of a webpage? I would like to get the source,
then use a regexp to find text on a webpage. For example, retrieving a
counter, or some other text that dynamically changes. I'm implementing this
for firefox.

right now, i have a web page opening that contains that info, but i would
rather have a pop up alert() that shows that info.

thanks for any help. and any code snippets would be great.
Sep 11 '05 #1
2 3295
doug s wrote:
How would I access the source of a webpage? I would like to get the source,
then use a regexp to find text on a webpage. For example, retrieving a
counter, or some other text that dynamically changes. I'm implementing this
for firefox.

right now, i have a web page opening that contains that info, but i would
rather have a pop up alert() that shows that info.

thanks for any help. and any code snippets would be great.


There are at least three ways of getting the text content of the document.

The standards-compliant method is to use document.body.t extContent, but
since it's DOM 3 it may not be widely supported beyond Mozilla/Firefox.

The IE-centric way is to use innerText as IE does not support textContent.

A third, reasonably cross-browser method is to use innerHTML and a
regular expression. But it's not a standard and different
implimentations may have small variations in how they've copied it from IE.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> blah </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<script type="text/javascript">

function showText( el )
{
var txt;
if ( el.textContent ) {
txt = 'textContent\n' + el.textContent;
} else if ( el.innerText ){
txt = 'innerText\n' + el.innerText;
} else if ( el.innerHTML ) {
txt = 'innerHTML\n' + el.innerHTML.re place(/<\/?.[^\>]*>/g,'');
}
return txt;
}

</script>
</head>
<body >
<div onclick="alert( showText( document.body ));">
Here is <div>the <span> content. <b>Hi</b></span>
<br>Click me to see the content.
</div>
</div>
</body>
</html>

--
Rob
Sep 11 '05 #2

"RobG" <rg***@iinet.ne t.au> wrote in message
news:jY******** *********@news. optus.net.au...
There are at least three ways of getting the text content of the document.

The standards-compliant method is to use document.body.t extContent, but
since it's DOM 3 it may not be widely supported beyond Mozilla/Firefox.

The IE-centric way is to use innerText as IE does not support textContent.

A third, reasonably cross-browser method is to use innerHTML and a regular
expression. But it's not a standard and different implimentations may
have small variations in how they've copied it from IE.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title> blah </title>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-1">
<script type="text/javascript">

function showText( el )
{
var txt;
if ( el.textContent ) {
txt = 'textContent\n' + el.textContent;
} else if ( el.innerText ){
txt = 'innerText\n' + el.innerText;
} else if ( el.innerHTML ) {
txt = 'innerHTML\n' + el.innerHTML.re place(/<\/?.[^\>]*>/g,'');
}
return txt;
}

</script>
</head>
<body >
<div onclick="alert( showText( document.body ));">
Here is <div>the <span> content. <b>Hi</b></span>
<br>Click me to see the content.
</div>
</div>
</body>
</html>

--
Rob


thanks. that helps. Is there a way to fetch a page, without actually opening
it, and then use showText(el) ? Somehow pass in the url ?

thanks again.


Sep 12 '05 #3

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

Similar topics

18
2312
by: Michael Skind | last post by:
Hello, I use a simple Table : <TABLE> <TR 1> <TD></TD> </TR> <TR 2> <TD></TD> </TR>
12
8437
by: who be dat? | last post by:
I'm trying to make a webpage do the following: I want a user to be able to click on a given image (there will be more than one image). Upon clicking a given image, characters specific to that image will be inserted into a textbox which is actually a text area. If the cursor is in the textbox/textarea then the characters are to be inserted at the cursor location. This means if the cursor is between some text then the characters need to...
2
1135
by: Hello | last post by:
How can I findouf the URL that the webpage came from? Thanks. Like document.address or something?
8
1762
by: nescio | last post by:
hello, i have a script that finds the x and y from the mouse position, this works fine. but now i have an image in a layer : <div id='someLayer'> <img src='someImage.jpg'> </div>
2
2853
by: ElkGroveR | last post by:
Hi there! I'm using PHP to create a simple, dynamic MySQL SELECT query. The user chooses a selection from a HTML Form SELECT element's many options and submits the form via a POST action. The SELECT query is built as follows: $itemtype = stripslashes(trim($_POST));
3
1819
by: Sharon | last post by:
hello all, I was successfull in passing one value from first webpage to second webpage, but not sure how to pass three textbox values from the first page to the second page. Below is the code i was using to pass a single value First WebPage: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
2
2555
by: Naha | last post by:
Hi Guys, Does anyone know how to display data from a text file onto a webpage? So far I have opened and read the data in the text file and printed it out on command line, but I am having difficulty of displaying the data from the text file on to the webpage.
4
5574
by: Finn Stampe Mikkelsen | last post by:
Hi Is there any way to make the textbox property show html, like a textarea on a webpage would?? I have a webapplication that saves an textarea complete with html tags and everything... Now i'm coding a windows application to work with the same data and i need these data to be displayed on an windows form, like they would on the
15
1975
by: rhino | last post by:
I've put together a prototype of two-tiered CSS tabs that works really well in IE6, IE7, and FF2. It also works very well in Opera 9.27 _except_ that the placement of the lower tier of tabs is messed up. Both the XHTML and CSS validate without any errors or warnings. Can anyone help me figure out what is wrong? I'd be especially interested in the technique you used to figure out where the problem was. I still struggle a lot when I try to...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5437
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.