usemod-search.pl 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #! /usr/bin/perl
  2. # Copyright (C) 2003 Alex Schroeder <alex@emacswiki.org>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. use CGI qw/:standard/;
  20. use CGI::Carp qw(fatalsToBrowser);
  21. use LWP::UserAgent;
  22. if (not param('url')) {
  23. print header(),
  24. start_html('UseMod Search RSS 3.0'),
  25. h1('UseMod Search RSS 3.0'),
  26. p('Translates a UseMod Search result into RSS 3.0 usable by Oddmuse.'),
  27. start_form(-method=>'GET'),
  28. p('Search URL: ', textfield('url'), submit()),
  29. end_form(),
  30. end_html();
  31. exit;
  32. }
  33. print header(-type=>'text/plain; charset=UTF-8');
  34. my $ua = new LWP::UserAgent;
  35. my $request = HTTP::Request->new('GET', param('url'));
  36. my $response = $ua->request($request);
  37. my $data = $response->content;
  38. $data =~ /\<title\>([^<]*)/i;
  39. print "title: $1\n" if $1;
  40. print "link: " . param('url') . "\n\n";
  41. while ($data =~ /\n\<a[^>]*\>([^<]*)\<\/a\>\<br\>/gi) {
  42. print "title: $1\n\n";
  43. }