ajosif Posted February 15, 2008 Share Posted February 15, 2008 Hi,I want to make a simple program that will search for one word inside the webpage something like:search("Geranium", "www.webpage.com")if found() write("www.123.com", "Geranium")Was told that cannot be don in javascript, but some more advanced language like Java.I don't need to run a website just execute a progam on my computer that will search the webpages.What is the simplest/easiest language that can do this? Java is too complicated for me.Thank you Link to comment Share on other sites More sharing options...
jeffman Posted February 15, 2008 Share Posted February 15, 2008 [edit: you might want to read the next message before bothering with this one.]I've never had the need to do anything like this, but I'm sure it can be done in javascript. If you're accustomed to recursive functions, you're halfway home.What you'll need to do is dig through the childnodes of the document body, and their nodes, etc., and test each one to see if it's a text node. If it is, do some sort of match or equality comparison. Then move on till you've hit every branch on the tree.I believe there are examples out there of "tree-walker" routines.Someone may even have a getTextNodes() function out there or a getNodesByType(), but these aren't built into the DOM, even though it seems obvious that they should be. If you're lucky, now that you know what to look for, you might find something. But it's writable with pretty basic programming skills. Link to comment Share on other sites More sharing options...
jeffman Posted February 15, 2008 Share Posted February 15, 2008 Oh dear. I just reread your post and think I may have misunderstood. You want to search someone else's page, not yours? Can't help you there. Link to comment Share on other sites More sharing options...
jesh Posted February 15, 2008 Share Posted February 15, 2008 You can use Java, PHP, C#, VB, perl, python, etc.. It could be either a web application or a desktop application. The process that needs to happen is that you tell your application the URL that you want to fetch and then it creates an HTTP Request and sends it off to that URL and retrieves the response. Then you parse through the text of the response looking for your search string.I'm partial to C# and have done something like this a number of times using either System.Net.WebClient, System.Web.HttpRequest, or System.Net.Sockets.TcpSocket.If this is for a web page, you can start looking at how people build AJAX proxies:http://www.google.com/search?q=ajax+proxy Link to comment Share on other sites More sharing options...
ajosif Posted February 15, 2008 Author Share Posted February 15, 2008 Hi,Yes, I want to search some other's webpages, there will be a listo of different web pages.Looks like there's no simple way to do that, have to learn more programming.In a web page I can manually view the source and search it, or just do Ctrl+F type the word and will highlight it if there.Thank you anyway, I was hoping it can be done in just a few lines of code. Link to comment Share on other sites More sharing options...
AElliott Posted February 15, 2008 Share Posted February 15, 2008 Well, it's fairly trivial once you know the languages, for example in PHP you might do it like this: <?php$sites = array( 'http://site1.com/index.html', 'http://site2.com/index.html' );foreach($sites as $site) if(strpos(file_get_contents($site),'SEARCHWORD') !== false) echo $site,' contains the term.',"\n";?> That will do pretty much what you are saying, of course you need a PHP parser to run it. Link to comment Share on other sites More sharing options...
Jamesking56 Posted February 15, 2008 Share Posted February 15, 2008 Why don't you just use CTRL+F when viewing a webpage? Link to comment Share on other sites More sharing options...
ajosif Posted February 15, 2008 Author Share Posted February 15, 2008 Hi,Thank you so much, that is really a few lines of code, and even allows more than one webpages, great.I am starting with PHP asap.Thank you again. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.