Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Check for popups in webpage

by teabag (Pilgrim)
on Jul 19, 2003 at 21:55 UTC ( #275943=note: print w/replies, xml ) Need Help??

in reply to Check for popups in webpage

Young Anonymous,

It's not about wanting and needing, but about sharing and contributing. So I'll help you out a little with this "working" script.
You'll have to change some things to get it working entirely with just perl instead of using system calls ;).

So it's up to you to:

  • look up what strict does and to implement it.
  • Look for what other javacode makes popups appear and implement the matching of it.
  • See why the LWP-module is so very nifty, and usefull if you don't have lynx ;).
And thus completely rewrite this quick and dirty example.

To speak with the unforgettable words of Janice Joplin, "Try-ha-ha-ha-ha, just a little bit harder".

#!/usr/bin/perl -w $url = "empty";#;) if ($ARGV[0]) { $url = $ARGV[0]; } if ($url eq "empty"){ print "Specify url like http:\/\/www.makemyhomewor\n"; exit; } open TEL, "lynx -source $url|"; @text = <TEL>; $darnpopup = "false"; # teabags full report ;) print "@text\n$url"; foreach $line(@text){ if ($line =~ m/{ print " probably has popups, (or some other lame javascript....)\n"; $darnpopup = "true"; } } if ($darnpopup ne "true"){ print " probably has no popups\n"; }

Hmm, I just realised fixing the above code sounds even like more homework then you're in for! hehe...

Sure there's more than one way, but one just needs one anyway - Teabag

Replies are listed 'Best First'.
Re: Re: Check for popups in webpage
by SyN/AcK (Scribe) on Jul 20, 2003 at 00:02 UTC

    Hmmm... I checked out the LWP Module and I was wondering how you intend to use this as a pop-up killer. Were you intending to use it to create a web browser? Maybe I'm missing something here, but this is very interested for me, and thanks for the note for LWP anyways since it looks like a really cool module.

      Whereas the title does did say 'popup killer', the actual requirement is "can check for popups in any other web page and report it". The script teabag provided simply grabs a web page and checks to see if the string is present and does something if it is. This definitely fills the requirement. The title, while eye catching, doesn't exactly describe the content very well, IMHO (i am fixing to consider it for retitling).

      Also, if you think LWP is cool, check out LWP::Simple and WWW::Mechanize.


      (the triplet paradiddle with high-hat)
Re: Re: Check for popups in webpage
by Anonymous Monk on Jul 20, 2003 at 07:32 UTC
    Hi , Thanks for ur help but let me specify u where I am stuck . I open a web page in netscape like or or any web page in the world. I then start my perl popup killer script . Now my problem lies in getting the text contents of the web page .How can I get the web page contents of or or any web page from the browser window .Mostly i can hard code the url which i don't want since I can open any web page in the browser and I want to retrieve the text contents of the opened web page in browser . Eg : If i open then i should be able to retrive the web contents i.e text and check for popup. If i open then i should be able to retrive the web contents i.e text and check for popup. Can u suggest me on how I can do it . Please let me know on the above problem . Bye

      Since, as was pointed out to you ( or someone like you) in another node, you'd need to have your script interact with the Netscape application, this is hard to make work on Unix.

      Therefore, your script would have to be a proxy, sitting between your Netscape and the Web, so it could see all the pages you retrieve and check them. Of course, if you judt want to kill the popups (and don't want to use Mozilla for some reason), you could use junkbuster - as this is a proxy that sits between your browser and the web watching what goes by and acting on it.

      Otherwise, tell your professor he's asking for the impossible (or near impossible).

      Update: You could run the code previously suggested in a loop that waited for a URL to be given on STDIN, then checked the page and repeated. Then you could copy and paste the URLs from the Location field in Netscape to the treminal where your script is running. Other than that, good luck.

      --Bob Niederman,

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2020-11-26 01:34 GMT
Find Nodes?
    Voting Booth?

    No recent polls found