ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to automate the above function / link along with the said URL so that I won't have to open the webpage and click the button / link.
I want a single URL hitting which we won't need to do the extra effort of "clicking the link / button" that executes the JavaScript function given above.
I can't automate this task in the source webpage itself because that has to be there as it is for the users who access the webpage.
Nope, guys! That is not what I want to do. The webpage is to be used as it is. Let's say to get a report I need to open that particular webpage and then click a link / button located on it. Clicking the link / button will then fetch a report and display it on the webpage or save it to a file automatically. That functionality is already in place and I can't touch it. So, this is what I want to automate. I need to visit the webpage and click that link/button over and again and then look for a particular piece of information (status). I want to simply automate this "clicking the link/button" task so that I won't have to visit the webpage at all.
If you hit this in (on Windows XP, for example) Start -> Run:
then it will open your default web-browser and the website/webpage will also be displayed in it. Or you can save that line in a .bat file and then have "Scheduled Tasks" run it from time to time. That is exactly what I am doing. But I need to include that "link / button", which is a JavaScrip function, with the line: explorer http://google.com so that that particular function can be executed as if the webpage had been manually opened and the button were clicked on.
Okay, so you have a webpage, downloaded from a web server. The web page can be downloaded either by a conventional web browser (explorer in your example, others possible), or by a simpler tool such as wget or curl. Within that web page is some javascript, and some HTML. The HTML describes a way in which a particular fragment of the javascript is invoked.
Since the HTML causes the screen element (a link) to invoke a javascript function, and since a link is interactively activated by a user, the problem seems to become one of how to get the function invoked unconditionally.
If the page is downloaded and saved to a disk file, it can be modified by a script in a way such as AnanthaP has described. Once modified, the page can then be loaded by a conventional browser as a file:// type URL. With luck, there will be enough information in the HTML file to unambiguously perform the action described in the javascript. It may be that the URL of the server that serves the initial page request needs to be retained, and is used by the browser to complete the execution of the javascript.
If the latter is the case, then the modification of the page as a static page will fail. The solution then would be to modify the page en-route to the browser. That would require some serious system-level hacking, and if Windows is the host, LQ is probably not the ideal place to pursue that avneue. Alternatively, there seems to be a few plugins and other extensions that fall in the category of 'web browser automation'. Google will reveal a number of them. Perhaps that is a viable solution to your problem.
By the way, how do we identify if a particular website is being hosted on or served by a Linux or Windows box?
I think you have misinterpreted my previous reply regarding the host OS. In that, I meant the OS hosting the client (browser), since it is there that you have access to the incoming HTTP data. In most cases there is no explicit identification of the server host OS or HTPP server within the HTTP data. There may be ways to divine the nature of the server based on undocumented behaviors, but I could not describe any of those. Blackhats often make use of such characteristics in order to determine applicable exploits.
Only the browser normally reports its identity, and this is commonly used server-side for producing compatible HTTP responses.
--- rod.
Okay, so I may have spoken too soon and too uninformed. Having just tried running nmap against a local HTTP server, I see that it correctly identifies the distro (but not version) of the server host OS and HTTP server type and version. Not too sure where it is getting that from; perhaps using techniques I alluded to in my previous post.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.