Posted on 2005-02-02 15:59:21-08 by ovid
Author and Maintainer
As the author and maintainer of HTML::TokeParser::Simple, I'm available for questions, bug fixes, etc. Just drop me a line here.
Direct Responses: 161 | Write a response
Posted on 2005-02-28 16:21:54-08 by rshandy in response to 5
Re: Author and Maintainer
Hi Ovid: I was reading through your module and its looks like it may help me with my problem. Unfortunately, I'm not very good at writing perl...here's my problem: I need to write translated values that are sent to browser to a text file. I have this test page: http://www.dog-crates.com/cgi-bin/write_test_softcart2.pl
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 SoftCar +t:"; 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:%%product(99901BB).micro_description%%%%product(99901BB).micro_description%%

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

Will the HTML::TokParser module help me achieve this??

your help would be greatly appreciated.

thanks,

rich
Direct Responses: 162 | Write a response
Posted on 2005-02-28 16:59:16-08 by ovid in response to 161
Re: Author and Maintainer

Hi Rich,

Try as I might, I can't quite figure out what you're trying to do here, but taking a stab at it, it seems like you're trying to strip HTML tags from the "selector2.txt" file? Is this correct? If so, a simple way of stripping tags from a chunk of text would be to do this:

use HTML::TokeParser::Simple 3.13; my $parser = HMTL::TokeParser::Simple->new(string => $html_text); my $text = ''; while (my $token = $parser->get_token) { next unless $token->is_text; $text = $token->as_is; }

At the end of the while loop, $text will contain only the visible text from $html_text. If this does not answer your question, try explaining the following four things:

1. What you are trying to do.
2. How you are trying to do it (with the smallest possible code snippet that shows the problem.
3. What results you expect.
4. What results you are getting.

Direct Responses: 164 | Write a response
Posted on 2005-02-28 21:18:00-08 by rshandy in response to 162
Re: Author and Maintainer
Hi Ovid:
Thanks for your response.
OOPS!! I feel really stupid. I didn't realize the server was down and therefore gave you an error on my test page:

AnywayHere's answers to your questions for clarity: 1. What are you trying to do.

I have a website that,on the product pages I change several values of div tags when the visitor clicks on a graphic (i.e. price, product name, etc). When I click on the graphic, the data is pull from an array in the header tag. SoftCart parses the pages and writes the interpreted value of this tag in the array. I'm now adding many more fields that have to change onclick. That would make the array quite large and take forever to load the page.

I want to be able to create an external .js file from a perl script call that will interpret only the product that the user clicks on

Here's a sample page of the product page:

http://www.dog-crates.com/scstore/product_test.html

Before I get ahead of myself, I first wanted to create a "standalone" perl script to write softcart interpreted data to a text file, namely, selector2.txt

This is where I'm at now...

So, I'm trying to strip the tags from the parsed html page and write the values to selector2.txt.(the reverse of what you thought).

the %%product(99901BB).micro_description%% is a softcart tag which needs SoftCart.exe to for it to intrepret it. In order for softcart.exe to run it's path is parsed in the url - adding the cgi-bin/SoftCart.exe in every page.

2. How I'm trying to do it

The code I posted is pretty straightforward for a quick snippet - now that the server is actually parsing the pages!! 3.What results you expect.

I expect the selector2.txt file to contain the interpreted data - and should look like this:

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.

4. What results you are getting.

This is what the file selector2.txt contains:

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

%%product(99901BB).micro_description%%%%product(99901BB).micro_description%% :

Well, I hope that makes things a little clearer. Let me know what you think. Thanks again. Rich
Direct Responses: 167 | Write a response
Posted on 2005-02-28 23:36:40-08 by ovid in response to 164
Re: Author and Maintainer

I have no idea the mechanism by which your text is being altered in the Web page output because what you are printing to the file is the same thing you're printing to the Web page. You appear to be using Mercantec SoftCart and they appear to be intercepting your requests and interpreting the information. Thus, by the time your script is done printing, the interpolated information is not yet present. This is not an HTML::TokeParser::Simple issue as the requisite data is not there to parse. I would recommend contacting your vendor for a solution.

Sorry. Ovid.

Direct Responses: 169 | Write a response
Posted on 2005-03-01 02:29:47-08 by rshandy in response to 167
Re: Author and Maintainer
Hi Ovid: I was afraid of that. Already contacted SoftCart;they didn't have a viable solution. Thanks for your patience. If I come up with something ingenious, I'll post it. Rich
Direct Responses: Write a response
Perl Weekly newsletter
A free weekly newsletter for people who are busy to read all the blogs. click here to check it out.