Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

writing same values that are displayed on browser

Status
Not open for further replies.

rshandy

Technical User
Dec 26, 2003
91
US
Can I possibly write the same values that are being displayed in the browser to a text file? The values end up different when I write to the file because the actual page has to be parsed for a data tag to be interpreted.

For example, if I call a simple test script:


here's the pl code:
#!/usr/bin/perl5
use strict;
use CGI qw:)standard);
my $upname10="selector10.txt";
print "Content-type: text/html\n\n";
print"<header>";
print<<DDPENWE1;
<title> crates test</title>

<SCRIPT LANGUAGE="JavaScript">

SCPath = "/cgi-bin/SoftCart.exe";
config = "scstore";
if (location.pathname.substring(0,SCPath.length)!= SCPath) {
window.location.replace(SCPath + location.pathname + "?E+" + config);
}

</Script>
</head>
<body>

DDPENWE1

my $description = "%%product(99901BB).micro_description%%";

open (File10, ">$upname10" || die "Error opening file $upname10");
print File10 "Below is the description of SKU 99901BB that has been properly interpreted by SoftCart:";
print "Below is the description of SKU 99901BB that has been properly interpreted by SoftCart:<br><br>";
print File10 "<b>%%product(99901BB).micro_description%%</b>";
print File10 $description;
print $description;
print "<b>%%product(99901BB).micro_description%%</b>";
close (File10);
print"</body>";
print"</html>";

If you click on the link, you'll see that the page gets reparsed so softcart can interpret the tag - the page displays the following:

Below is the description of SKU 99901BB that has been properly interpreted by SoftCart:

The smallest of the lifestyle series, this 2 liter twin turbo really packs a wallop. Able to leap tall buildings with a single bound. Use this crate for small dogs, such as pekinese, Yorkies, and fendermen benz.The smallest of the lifestyle series, this 2 liter twin turbo really packs a wallop. Able to leap tall buildings with a single bound. Use this crate for small dogs, such as pekinese, Yorkies, and fendermen benz.

The text file that I write to however, selector2.txt, displays the following:

Below is the description of SKU 99901BB that has been properly interpreted by SoftCart:<b>%%product(99901BB).micro_description%%</b>%%product(99901BB).micro_description%%

How can I write the "interpreted" version to the selector2.txt file.

your help would be greatly appreciated.

thanks,

rich
 
Your output to the file is different from what displays in the browser becuase when it is displayed in the browser there is java code that changes the text. When you save it to a file the java code does not alter the text because java is not running. You will need to process the java before you print the text to a file.


Michael Libeson
 
I thought I was doing that. Doesn't the js process in the head tag first and then the body of document gets processed?

my $description = "%%product(99901BB).micro_description%%";
displays the value of the %% tag when I print to the browser but displays the jsut tag name when I write it to file. These print calls are right next to each other in the code -

What am I missing?

Rich
 
The bowser runs java to change the text, but that does not exist in the PERL environment, so that when you write to a file the text has not been translated. The translation is happening within the browser not in your code. Your code only provides the data and translation rules.


Michael Libeson
 
Thanks Michael:

So there's no way to get the translated data to a file on my server?

Would the HTML::TokeParser::Simple module help me any way?

I am in such a pickle with, as I need to somehow get the translated data written to file.

Thanks again.

Rich
 
You will need to emulate what the java codes does in the browser while you are writing to the text file. Can you translate the text from the command line using java?
If so, then run it using "open(jv, "java a.js |")" so that you can capture the output. There might be another way, I just do not know how. Have you checked the LWP modules or searched CPAN?


Michael Libeson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top