JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 6th, 2013, 05:30 PM
memo0o0 memo0o0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 10 memo0o0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 13 sec
Reputation Power: 0
Help me please??

can anyone help me how can I extract text from webpage and count occurence of the words and the result should display in table and user should select if the order is alphapatic or frequencey please help me ??
thanks in advance

Reply With Quote
  #2  
Old February 7th, 2013, 12:47 AM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 605 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 3 m 14 sec
Reputation Power: 69
This will let you define the word your looking for and display results accordingly:

Code:
<!DOCTYPE html>
<html>
<head>

<script>

var count = 0;

var cached="no";

function counter(word,counTitle,wordTitle)
{

content = document.getElementsByTagName("body")[0].innerHTML.split(" ");

for (i=0;i<content.length;i++) {
content[i] = content[i].replace("\n"," ");
if (content[i].match(word)) {
count++;
}
}

var countHeadingRow = document.createElement("tr");
var HeadingTD = document.createElement("td");
var HeadingTD2 = document.createElement("td");
var newTR = document.createElement("tr");
var newTD = document.createElement("td");
var newTD2 = document.createElement("td");

HeadingTD.innerHTML = counTitle;
HeadingTD2.innerHTML = wordTitle;
newTD.innerHTML = count;
newTD2.innerHTML = word;

// create heading

if (cached != "yes") {
document.getElementById("wordData").appendChild(countHeadingRow);
document.getElementById("wordData").getElementsByTagName("tr")[0].appendChild(HeadingTD);
document.getElementById("wordData").getElementsByTagName("tr")[0].appendChild(HeadingTD2);
cached="yes";
}

// create new data rows for each word/quanity

document.getElementById("wordData").appendChild(newTR);
var maxRows = document.getElementById("wordData").getElementsByTagName("tr").length - 1;
document.getElementById("wordData").getElementsByTagName("tr")[maxRows].appendChild(newTD);
document.getElementById("wordData").getElementsByTagName("tr")[maxRows].appendChild(newTD2);

// reset all

count = 0;
content = [];

}

document.onreadystatechange = function() {

if (document.readyState=="complete") {

// add "counter" function and define parameters, too find case sensitive words & word quanities

counter("rock","Amount Displayed","Word Displayed");
counter("wanna","Amount Displayed","Word Displayed");
counter("Turn","Amount Displayed","Word Displayed");
counter("go","Amount Displayed","Word Displayed");
counter("Go","Amount Displayed","Word Displayed");
counter("No","Amount Displayed","Word Displayed");

}

}

</script>


</head>

<body>

<!-- demo content - begin -->

<pre style="text-align:center">
I wanna rock! rock!
I wanna rock! rock!
I want to rock rock!
I wanna rock! rock!

Turn it down you say,
Well all I got to say to you is time again I say, "No!"
No! No, No, No, No, No!
Tell me not to play
Well, all I got to say to you when you tell me not to play,
I say, "No!"
No! No, No, No, No, No!
So, if you ask me why I like the way I play it
There's only one thing I can say to you

I wanna rock! rock!
I wanna rock! rock!
I want to rock rock!
I wanna rock! rock!

There's a feelin' that
I get from nothin' else and there ain't nothin' in the world
That makes me go!
Go! Go, go, go, go, go!
Turn the power up
I've waited for so long so I could hear my favorite song so,
Let's go!
Go! Go, go, go, go, go!
When it's like this I feel the music shootin' through me
There's nothin' else that I would rather do

I wanna rock! rock!
I wanna rock! rock!
I want to rock rock!
I wanna rock! rock!
</pre>

<!-- demo content - end -->


<br/>
<br/>
<br/>

<table id="wordData" border="1" width="100%"></table>

</body>

</html>

Reply With Quote
  #3  
Old February 7th, 2013, 08:10 AM
memo0o0 memo0o0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 10 memo0o0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 13 sec
Reputation Power: 0
Thanky fo helping but the count should be from another web page so it let user to type the url of the page to count and the result should be in a table .... How can I solve this

Reply With Quote
  #4  
Old February 7th, 2013, 07:32 PM
web_loone08's Avatar
web_loone08 web_loone08 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2008
Posts: 605 web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level)web_loone08 User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 16 h 3 m 14 sec
Reputation Power: 69
You could go about doing this a couple different ways, but the main idea is..., that your going to have to scrape the page's content and get text/responseText back into the "content" variable. You can set-up a server side page to get the content's of a page once it has been queried. A basic example in my chosen server side language would be:

PHP Code:
scrapper.php
<?php
header
("Content-Type:application/javascript");
$defineURL $_GET["url"];
$contents file_get_contents("".$defineURL."");
if (isset(
$defineURL)) {
echo 
"var content=\"$content\";\n\n";
}
else {
echo 
"var content=\"No Content Found!\";\n\n";
}
?>


Then add this to your page (remove the content variable declaration; that I originally had in the code.... ie. "var content;"); with an external javascript link... ie. "<script type="text/javascript" src="scrapper.php"></script>" or you could get the responseText with AJAX and insert it into the "content" variable.

Or... an alternative would be to use and incorporate the YQL Module for YUI; which is a screen scraper plugin/API from Yahoo's YUI 3.0 Framework.

Or... you could screen scrape the page and serve it as plain text or html and include it in an iframe (within the page the search is occurring from) and then have the "content" variable store the innerHTML of the contentWindow || contentDocument of the iframe.

Or... you could just do away with the client side aspect (javascript) and do this completely server side. In my opinion, this option... would be the best way to go.

So... yeah, you have several ways you could do this. Do some online searching for "screen scraping" and/or "server side screen scraping" and/or "client side screen scraping" and/or "ajax screen scraping" and/or "javascript screen scraping". Those are all good places to start from... good luck.

Reply With Quote
  #5  
Old February 8th, 2013, 06:57 AM
memo0o0 memo0o0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 10 memo0o0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 13 sec
Reputation Power: 0
I have put the code to get the url from the user to count
however i do not know what should I have to put in the counter()??? to diblay the result
here is my code
[code]
<!DOCTYPE html>
<html>
<head>

<script>

var count = 0;

var cached="no";

function counter(word,counTitle,wordTitle)
{

content = document.getElementsByTagName("body")[0].innerHTML.split(" ");

for (i=0;i<content.length;i++) {
content[i] = content[i].replace("\n"," ");
if (content[i].match(word)) {
count++;
}
}

var countHeadingRow = document.createElement("tr");
var HeadingTD = document.createElement("td");
var HeadingTD2 = document.createElement("td");
var newTR = document.createElement("tr");
var newTD = document.createElement("td");
var newTD2 = document.createElement("td");

HeadingTD.innerHTML = counTitle;
HeadingTD2.innerHTML = wordTitle;
newTD.innerHTML = count;
newTD2.innerHTML = word;

// create heading

if (cached != "yes") {
document.getElementById("wordData").appendChild(countHeadingRow);
document.getElementById("wordData").getElementsByTagName("tr")[0].appendChild(HeadingTD);
document.getElementById("wordData").getElementsByTagName("tr")[0].appendChild(HeadingTD2);
cached="yes";
}

// create new data rows for each word/quanity

document.getElementById("wordData").appendChild(newTR);
var maxRows = document.getElementById("wordData").getElementsByTagName("tr").length - 1;
document.getElementById("wordData").getElementsByTagName("tr")[maxRows].appendChild(newTD);
document.getElementById("wordData").getElementsByTagName("tr")[maxRows].appendChild(newTD2);

// reset all

count = 0;
content = [];

}

document.onreadystatechange = function() {

if (document.readyState=="complete") {

// add "counter" function and define parameters, too find case sensitive words & word quanities


}

}

</script>


</head>

<body>
<p>Web Page URL : <input id = "url" name="url" size=25 type="Text"/></p>
<a href="javascript:coutner(document.getElementById('url').value)"> count word in document document</a></br>
<table id="wordData" border="1" width="20"></table>

</body>

</html>[code]

Reply With Quote
  #6  
Old February 8th, 2013, 07:12 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,864 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 21 h 20 m 24 sec
Reputation Power: 813
Hi,

please read the replies you get. web_loone08 has made a long list of possible solutions, which you just ignored.

You cannot access other domains with JavaScript. It's not allowed. If it was, that would be a horrible security hole, because other websites could use JavaScript to telecontrol your browser and, for example, make PayPal transactions on your behalf. So what you're trying there is impossible.

If you want to count words on another domain, you need a server script (written in PHP or whatever). But web_loone08 already said this, so simply read his post.

Reply With Quote
  #7  
Old February 8th, 2013, 07:45 AM
memo0o0 memo0o0 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2013
Posts: 10 memo0o0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 52 m 13 sec
Reputation Power: 0
because what I mean is get text from other html file and count the occurence of the word using java script ??

Reply With Quote
  #8  
Old February 8th, 2013, 07:57 AM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,864 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 21 h 20 m 24 sec
Reputation Power: 813
I understand what you're trying to do, but you cannot do this with JavaScript. You just can't. It's impossible. It's not allowed for security reasons.

You need to count the words on your server with PHP or Ruby or Python or Perl or whatever server-side scripting language you are familiar with.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Help me please??

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap