How to include CGI script inside HTML document? - perl

I have to include my CGI script login.pl inside an HTML document index.html. I googled for answers and was surprised to find out that it was hard to get a definitive answer to this question. Some suggest using server side includes, but as far as I understand those are used for putting HTML inside of CGI, which is not what I want. I know that in JSP and PHP one can use tags like <% %> and php tags to include code inside of HTML document. Is there a similar construct for CGI? P.S. I am using CGI.pm framework and want to run output of login.pl inside of index.html.

What you are looking for is HTML::Template or Template::Toolkit. Either of these will allow you to put tags in your HTML file and your CGI script can populate the data.
Note that you will be posting to or getting from the CGI script which will read the HTML file, populate it and then send built HTML file to the client. The client's browser would not be accessing the HTML file directly.
In your case, the client's browser will post to login.pl and then, on the server, the perl script will run and build the HTML file and serve it to the client.

It's not possible. CGI is a method for invoking scripts or programs on the server.
See https://en.wikipedia.org/wiki/Common_Gateway_Interface
PHP, ASP and JSP as special documents which are parsed by an interpreter on the server side which then executes the included code. HTML documents cannot be executed, thus, it's not possible.
However, you could make use of Server Side Includes (SSI, https://en.wikipedia.org/wiki/Server_Side_Includes) and include/call CGI programs from there - it's however, less powerful than PHP, JSP and ASP).

Related

how to hide unnecessary html tags in perl cgi when running from command line?

I'm using perl version 5.18. I don't have a provision to upgrade perl to a newer version. When I pass the CGI query parameters from the command line, the script runs and works perfectly but it shows unnecessary HTML tags and other things (<!DOCTYPE html PUBLIC...), which I want to hide from terminals. Those are necessary to execute the script from a browser. So, without affecting the functionality of cgi when it runs from the browser, is there any easy way to get only necessary outputs when running from command line/ terminal?
The best approach here is to separate the data extraction from the presentation of the extracted data.
I would move the data extraction code into a module. You can then call that module from your CGI program and then wrap it in the appropriate layer of HTML.
You can then write a command-line version of your program that uses the same module to extract the correct data but which then wraps it in whatever text you want to use to display the data on the console.
Adding unwanted presentation layers (like your current HTML) is never a good idea. Best to rewrite from scratch to give what you want.
(If you're in a real rush though, there's one other approach that I might consider. Write a screen-scraper that scrapes your HTML page and extracts the data from that.)

How can I "drill down" into a website using Perl's WWW::Mechanize

I have used the WWW::Mechanize Perl module on a number of projects and it's helped me out a lot.
I am trying to use it on a different site and I can't "drill down" into the content of the site.
The site is https://customer.bookingbug.com/?client=hantsrecyclingcentres#/services
I have tried figure out what the URL would be to get content shown in the resulting HTML, such as bb.d570283b87c834518ba9.css, bb.d570283b87c834518ba9.js and version.js
I tried to copy the resulting HTML into this posting, but used all sorts of quote and code sample combinations and it wouldn't display properly.
Does anyone have any idea how I "navigate" this site using this Perl module please?
WWW::Mechanize is a web client with some HTML parsing capabilities. But as you clearly noticed, the information you want is not in the HTML document you requested. Either download the correct document (whatever that might be), or do what the browser does and execute the JavaScript. This would require a JavaScript engine. The simplest way to achieve that is to remote-control a web browser (e.g. using Selenium::Chrome).

How do I crawl a website written in JSP (Java Server Pages) using Perl Script?

I have here this website:https://www.connect2nse.com/iislNet/UserFolder.jsp
Firstly i tried using WWW::Mechanize, but it doesn't seem to work. WWW::Mechanize doesn't work with JSP written website. So I researched about how to download a file in a website written in JSP, but can't find a good one. Can anybody help me with this one? Thanks in advance.
As far as the client is concerned, JavaServer Pages is identical to PHP, Perl, or even static HTML files. The result is a page of HTML that can be rendered and displayed, and the source of the data isn't the reason for WWW::Mechanize failing to do what you want
Doesn't work is useless as a problem description, and the issue could be pretty much anything. However, if the HTML is associated with some JavaScript (which is executed on the client system after the page has been retrieved and not on the server) then it may be more or less handicapped because WWW::Mechanize doesn't support JavaScript. For that you will need to use WWW::Mechanize::Firefox or similar, which works by using a real instance of Firefox to render the HTML and execute any JavaScript

perl - processing template files to html

I am new to web programming but have experience working on perl scripts that have to do with file processing. Recently got a copy of MVC project source code. As I am trying to come to terms with template files, control & view modules, one question that came across is:
I see the template file in .tt extension(mypage.tt), there is the control module in .pm extension(MyPage.pm)) containing handler function to call the template and call to process subroutine in the View module(View.pm). But how does it generate .pl or html. I can't seem to find a perl executable or html file in the project. What should i enter in my url under
localhost/myapp/....
to call execute the script
I have loaded the project in my local directory with apache & mod_perl installed. Would be helpful if someone can explain if i need to write a perl script to call the handler function in the .pm file and generate the html if that's not too much to ask for :).
You project, if it is really a mod_perl app will have Apache configuration that maps URLs to handler methods.
Template files with a .tt extension typically are from the Template Toolkit, and perform their generation step by calling a method called process() on an instance of Template.
So you need to find the Apache handlers. They will tell you which methods are running, and then you can read hose methods to see how the template toolkit is being employed to generate the HTML.

Launching a GWT module when clicking on an XML

Greetings,
I'm looking for a way to launch a GWT module when a user clicks on an XML file and have the module consume the xml data. Ideally I would like to render the XML in a rich manner and would prefer to use GWT controls instead of having to lay it out by hand via xslt + javascript.
I'm supposing one way would be to point the xml to a well known xslt that creates a simple html page that forces a redirect to the gwt module but how would I transfer the xml data to said module to allow for enhanced formatting?
Another way would be to have the process that produces the xml also include the bootstrap gwt module but it would be creating multiple bootstrap instances over time and pollute the user's directory.
The use case is that a user would run this app on their local machine which outputs an XML file. If they try and view the xml file in a browser, I'd like to have the GWT module take over and present the data accordingly. I would rather they not have to go to a page and upload the data manually.
Appreciate any ideas on the matter.
TIA
If it's something that runs on the user's machine, I would recommend to ship an executable, or generate a parallel HTML file to present the data. JavaScript run from file:/// will not be able to acces the filesystem.