/[swish]/trunk/spider/swishspider
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/spider/swishspider

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Tue Jun 4 06:39:53 2002 UTC revision 40 by dpavlin, Sun Jun 1 11:45:19 2003 UTC
# Line 18  my $url = shift; Line 18  my $url = shift;
18    
19  my $no_parent_url;  my $no_parent_url;
20  if ($url =~ m/\s/) {  if ($url =~ m/\s/) {
21          ($url,$no_parent_url) = split(/\s/,$url,2);          ($no_parent_url,$url) = split(/\s/,$url,2);
22            # old scheme had URL, no parent and new is reverse
23            ($url,$no_parent_url) = ($no_parent_url,$url) if ($no_parent_url =~ m/$url/);
24  }  }
25    
26  my $request = new HTTP::Request( "GET", $url );  my $request = new HTTP::Request( "GET", $url );
# Line 39  if( $response->code() == RC_OK ) { Line 41  if( $response->code() == RC_OK ) {
41          if ($no_parent_url) {          if ($no_parent_url) {
42                  if ($link =~ m/$no_parent_url/) {                  if ($link =~ m/$no_parent_url/) {
43                          # if this URL is below parent URL o.k....                          # if this URL is below parent URL o.k....
44                          print RESP "$link $no_parent_url\n";                          print RESP "$no_parent_url $link\n";
45                  } else {                  } else {
46                          # if not, crawl just this page!                          # if not, crawl just this page!
47                          print RESP "$link $link\n";                          print RESP "$link $link\n";
# Line 59  if( $response->code() == RC_OK ) { Line 61  if( $response->code() == RC_OK ) {
61      my $contents = $response->content();      my $contents = $response->content();
62    
63      open( CONTENTS, ">$localpath.contents" ) || die( "Could not open contents file $localpath.contents\n" );      open( CONTENTS, ">$localpath.contents" ) || die( "Could not open contents file $localpath.contents\n" );
64      $contents =~ s,<noindex>.+?</noindex>,,isg;      # fixup just HTML files
65      $contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*/noindex\s*-->,,isg;      if ($response->header("content-type") =~ "text/html") {
66      $contents =~ s,<script>.+?</script>,,isg;          # if you don't want content to be indexed, include it in
67      $contents =~ tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/;     # 1250 -> iso8859-2          # <noindex> foobar </noindex> tags or surround it with comments
68            # <!-- noindex --> foobar <!-- /noindex -->
69            $contents =~ s,<noindex>.+?</noindex>,,isg;
70            $contents =~ s,<!--\s*noindex\s*-->.+?<!--\s*/noindex\s*-->,,isg;
71            # this will remove all script from indexing content
72            $contents =~ s,<script>.+?</script>,,isg;
73            # remap Windows charset to ISO-8859-2
74            $contents =~ tr/šðžèæŠÐŽÈÆ/¹ð¾èæ©Ð®ÈÆ/; # 1250 -> iso8859-2
75            # this will fix badly formatted html in form:
76            # <head><title>some text</title
77            # ></head>
78            # which will confuse indexer (or libxml2?)
79            $contents =~ s/[\n\r]^(>)/$1\n/msg;
80            # remove comments between <html> and <head> texi2html inserts them
81            # there and swish can't find document title then (libxml or swish bug?)
82            while ($contents =~ s/(<html>.*)<!--.*?-->(.*<head>)/$1$2/msi) { };
83        }
84      print CONTENTS $contents;      print CONTENTS $contents;
85      close( CONTENTS );      close( CONTENTS );
86    
# Line 78  if( $response->code() == RC_OK ) { Line 96  if( $response->code() == RC_OK ) {
96    
97  sub linkcb {  sub linkcb {
98      my($tag, %links) = @_;      my($tag, %links) = @_;
99      if (($tag eq "a") && ($links{"href"})) {      if (($tag eq "a" || $tag eq "area") && ($links{"href"}) || ($tag eq "frame" && $links{"src"})) {
100          my $link = $links{"href"};          my $link = $links{"href"} || $links{"src"};
101    
102          #          #
103          # Remove fragments          # Remove fragments
# Line 98  sub linkcb { Line 116  sub linkcb {
116          # hack for Apache directory listings          # hack for Apache directory listings
117          $link =~ s,/\?[NMSD]=[AD]$,/,g;          $link =~ s,/\?[NMSD]=[AD]$,/,g;
118    
119            # speedup, skip pictures
120            return if ($link =~ m/\.(gif|jpg|png)/);
121    
122          if ($no_parent_url) {          if ($no_parent_url) {
123                          if ($link =~ m/$no_parent_url/) {                          if ($link =~ m/$no_parent_url/) {
124                                  print LINKS "$link $no_parent_url\n";                                  print LINKS "$no_parent_url $link\n";
125  #                               print STDERR "using $link\n";  #                               print STDERR "using $link\n";
126  #                       } else {  #                       } else {
127  #                               print STDERR "skipping $link\n";  #                               print STDERR "skipping $link\n";

Legend:
Removed from v.1  
changed lines
  Added in v.40

  ViewVC Help
Powered by ViewVC 1.1.26