Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Parsing HTML code for formatting into JavaScript

by moritz (Cardinal)
on Feb 10, 2009 at 16:51 UTC ( [id://742817]=note: print w/replies, xml ) Need Help??


in reply to Parsing HTML code for formatting into JavaScript

What have you tried so far?

Also last time I looked it violated google's terms of services to use anything but the unmodified adsense code, and they can be very picky when you violate their TOS (ie they can, and probably will, block your account).

  • Comment on Re: Parsing HTML code for formatting into JavaScript

Replies are listed 'Best First'.
Re^2: Parsing HTML code for formatting into JavaScript
by anxara (Initiate) on Feb 10, 2009 at 17:00 UTC
    This is what I have tried so far, but it can only format the second <script> tag into something that can be put into a document.write() statement:

    sub html_to_js_var { my($vars) = shift; # Declare my @html = split(/\n/, $vars->{'html'}); my $var = $vars->{'js_var'}; my $in_quotes = $vars->{'in_quotes'}; # A value of either 'single' + or 'double' for ' or " respectively # Format foreach my $line (@html) { if ($in_quotes eq "single") { $line =~ s/\'/\\\'/g; $line =~ s/\</\<\'\+\'/g; } elsif ($in_quotes eq "double") { $line =~ s/\"/\\\"/g; $line =~ s/\</\<\"\+\"/g; } } return @html; }

    It doesn't actually isolate the first <script> section but would instead parse everything passed to it. Btw, it would be called like so:

    my @js_code = html_to_js_var({ "html" => $html, "in_quotes" => "single" # Could be "double" });

    What I am trying to do is display Google AdSense ads (or other ads) on my website and others, in a rotation with other ads. I know this is somehow possible (without violating Google's rules) b/c the PHP program OpenX ad server does it.
      What I am trying to do is display Google AdSense ads (or other ads) on my website and others, in a rotation with other ads. I know this is somehow possible (without violating Google's rules) b/c the PHP program OpenX ad server does it.

      It is possible with server side scripts - for example the server could keep a list of five ad snippets, and randomly deliver one of them on each request. That way the client always sees the unmodified HTML+JS that Google gave you.

      It's also a bit simpler to implement, because it doesn't imply parsing HTML.

        I am familiar with SSI but a lot of the sites the ads will be displayed on do not support SSI nor will they have access to the original perl script. This is why I am trying to display the ad through a <script src="..."> method as opposed to SSI.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://742817]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-25 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found