Click to See Complete Forum and Search --> : noob question
MargaretWilhelm
11-18-2004, 06:46 AM
i was told there is a way i can use javascript to read words on webpages and do a certain action when a certain word shows up?
say if i was on e-bay and it scanned the page for the word "outbid" and found it,it would click on the bid button and bid
is this possible to do?
i am ready to read and learn to do this
i dunno if you can do this, but i was told you could have script that refreshes a page and scans it for words then depends on the words will do actions
Charles
11-18-2004, 07:04 AM
For security reasons JavaScript runs in something like a sand box. You cannot use it to monkey with other people's pages.
MargaretWilhelm
11-18-2004, 07:05 AM
i wasn't going to play with other people's pages
i just wanted something that refreshed a page scaned for a certain word and then hit a button or clicked a link
Charles
11-18-2004, 07:16 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
<script type="text/javascript">
<!--
if (document.getElementById) onload = function () {
var body = document.getElementsByTagName ('BODY')[0];
var e, i = 0, n = 0;
while (e = body.getElementsByTagName ('*')[i++]) {if (/\best\b/i.test (e.firstChild.data)) n += e.firstChild.data.match (/\best\b/ig).length}
if (n) {alert (n)}
}
// -->
</script>
</head>
<body>
<p>Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus, qui sequitur mutationem consuetudium lectorum. Eodem modo typi, qui nunc nobis videntur parum clari, fiant sollemnes in futurum. Investigationes demonstraverunt lectores legere me lius quod ii legunt saepius. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. Nam liber tempor *** soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam; est usus legentis in iis qui facit eorum claritatem. </p>
</body>
</html>
MargaretWilhelm
11-18-2004, 07:24 AM
sorry but that doesn't help
TheBearMay
11-18-2004, 07:25 AM
Try this then:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Search Page</title>
<script type="text/javascript">
/*<![CDATA [*/
function getFile(fileName){
oxmlhttp = null;
try{
oxmlhttp = new XMLHttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e){
try{
oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e){
return null;
}
}
if(!oxmlhttp) return null;
try{
oxmlhttp.open("GET",fileName,false);
oxmlhttp.send(null);
}
catch(e){
return "<span style='font-size:xx-large;color:red'> ERROR: "+e.name + " - " + e.message+"</span>";
}
return oxmlhttp.responseText;
}
function checkPage(){
document.getElementById("iPut").innerHTML = getFile(document.getElementById("searchPath").value);
var found=document.getElementById("iPut").innerHTML.search(document.getElementById("searchVal").value);
if(found > 0) alert("Phrase found at position: "+found);
else alert("Phrase not found");
}
/*]]>*/
</script>
</head>
<body>
<div>
Depth:<input id="searchVal" value="search for" size="20" type="text" />
Path:<input id="searchPath" value="http://" size="40" type="text" /><br />
<button onclick="checkPage()">Click to Start</button>
</div>
<div id="iPut" style="border:12px outset red;"></div>
</body>
</html>
MargaretWilhelm
11-18-2004, 07:26 AM
nothing fancy with this stuff right? i mean just C & P the text into notepad and name it something.html
TheBearMay
11-18-2004, 07:27 AM
That should do it....
MargaretWilhelm
11-18-2004, 07:34 AM
it's not finding text on the site
it says "phrase not found"
it goes to any site i put in though but doesn't find text or links
TheBearMay
11-18-2004, 07:38 AM
The way it's set up now it's case sensative. Could that be the problem?
MargaretWilhelm
11-18-2004, 07:45 AM
ok i got it to find words
"Phrase found at position: 1892"
that is kinda the tip of the iceberg for what i am trying to get
is there code that will refresh the page every X amount of seconds and after each refresh scan for the word? and if the word is found click on a link?
TheBearMay
11-18-2004, 07:55 AM
Could add:
setTimeOut("checkPage();",5000);
at the end of of the checkPage function and replace the if block with:
if(found > 0) document.location.href="http://newURL";
MargaretWilhelm
11-18-2004, 08:17 AM
function checkPage(){
document.getElementById("iPut").innerHTML = getFile(document.getElementById("searchPath").value);
var found=document.getElementById("iPut").innerHTML.search(document.getElementById("searchVal").value);
if(found > 0) document.location.href="http://newURL";
else alert("Phrase not found");
i got the If worked out and redirect to the site i want if i change the document.location.href="http://newURL"; to document.location.href="http://www.siteiwant.com";
but just not the refresh
where do i put that?
TheBearMay
11-18-2004, 08:33 AM
Right after the else line and before the }.
MargaretWilhelm
11-18-2004, 08:38 AM
do i need another IF ELSE to make it so that if the phrase is not found it will reload the url i put in the top until the phrase is found? then continue with the redirect to the
if(found > 0) document.location.href="http://url.com"; page?
sorry but i might have not used the right words to say what i wanted it to do
the refresh i want for when the word is not found and i want it to refresh until the word is found and then use the above IF to redirect to the url
TheBearMay
11-18-2004, 08:42 AM
Shouldn't have to. If the phrase is found you'll be redirected and the timer is not reset; if not you'll drop through and reset the timer, and it will re-execute the checkPage() function.
TheBearMay
11-18-2004, 08:43 AM
BTW - If you don't want an alert each time you can eliminate the else line completely.
MargaretWilhelm
11-18-2004, 09:08 AM
i am testing it...
MargaretWilhelm
11-18-2004, 09:15 AM
it doesn't refresh the page and scan for the word
is there code to refresh the site i can put in along with the refresh for the search?
TheBearMay
11-18-2004, 09:26 AM
The page being searched should be reloading each time. May be a cache issue...
MargaretWilhelm
11-18-2004, 09:27 AM
i will try again but it wasn't reloading the page and searching
i used a page and updated it and nothing
MargaretWilhelm
11-18-2004, 09:32 AM
}
function checkPage(){
document.getElementById("iPut").innerHTML = getFile(document.getElementById("searchPath").value);
var found=document.getElementById("iPut").innerHTML.search(document.getElementById("searchVal").value);
if(found > 0) document.location.href="http://www.url.com";
setTimeOut("checkPage();",5000);
}
that is what i have code wise
TheBearMay
11-18-2004, 09:47 AM
Works for me. You could try this though:
var srchNum=0;
function checkPage(){
srchNum++;
document.getElementById("iPut").innerHTML = "<p style='font-size:large;color:red'>Search number: "+srchNum+"</p>"+getFile(document.getElementById("searchPath").value);
var found=document.getElementById("iPut").innerHTML.search(document.getElementById("searchVal").value);
if(found > 0) document.location.href="http://www.url.com";
setTimeOut("checkPage();",5000);
}
MargaretWilhelm
11-18-2004, 09:53 AM
it's not refreshing the webpage and then searching
sorry if i didn't make it clear
what about code to refresh the webpage and to refresh the search if the word is not found
i'm sorry if i sound like a *****
TheBearMay
11-18-2004, 10:01 AM
Guess what I'm trying to say is that the code above will, absent outside influences, re-fetch and reload the page being searched every time. If, however, you're going through a proxy server or any other device that caches the page, it may take a while to see the results. In the second set of code I added a search counter just to show that page is being reloaded, but again, if it's reloading a cached page it will take a while to change the data it's getting.
MargaretWilhelm
11-18-2004, 10:08 AM
ok thank you so so so much
i can use that right now thank you
MargaretWilhelm
11-18-2004, 10:12 AM
1 more thing
is there code that i can put in so that when it does find a word it will click a button or link?
code like the
if(found > 0) document.location.href="http://www.url.com";
say something like
if(found > 0)clicklink"Main"?
MargaretWilhelm
11-18-2004, 10:16 AM
bah
it's still not refreshing the IE page
i am working with a .php site and updating 1 word with lower or uppercase letters and the search count is going up and it's not refreshing the webpage
what's the code so it refreshes the page when i click the search button then searches?