BLOGinSPACE
インストール型ブログ
セキュリティコード
GoogleSitemapsジェネレータ
サイト探索
Google Sitemaps
Flash programming リンク集
Perl & CGI リンク集
PROGRAMING リンク集
プログラミング言語の種類
ActivePerl
Perlドキュメント(和訳)
Perlデータ構造
Apache JP
Apache 中核機能
http://www.bloginspace.com/続きを読む : "インストール型ブログ"
続きを読む : "セキュリティコード"
前回のサイト探索からの続きで
Google Sitemaps用のXMLファイルを出力するスクリプトを作ってみた(コマンド編)
強調されている行番号は前回(サイト探索)からの変更点
Code: download
- use LWP::Simple qw(get head);
- use HTML::LinkExtor;
- use strict;
- my(%seen,%mod_time,%out,$site,$top_url,$freq,$priority);
- $freq = 'weekly';
- $priority = '1.0';
- $top_url = 'http://sieg.xeong.com/';
- $top_url = "http://$top_url" unless $top_url =~ /^https?\b/;
- ($site = $top_url) =~ s/^(http:\/\/.+\/).*$/$1/;
- $site .= "/" unless ($site =~ /\/$/);
- &print_xml_head;
- linker($top_url);
- &print_xml_foot;
- sub linker {
- my $base_url = shift;
- my $parser = HTML::LinkExtor->new(undef, $base_url);
- $parser->parse(get($base_url))->eof;
- my @links = $parser->links;
- for my $linkarray (@links) {
- my @element = @$linkarray;
- my $elt_type = shift @element;
- while(@element) {
- my ($attr_name, $attr_value) = splice(@element, 0,2);
- if( $attr_name eq "href" && $attr_value->scheme =~ /\b(https?)\b/ && $attr_value =~ /^$site/
- && ($attr_value =~ /\.xml?$/i or $attr_value =~ /\.s?html?$/i or $attr_value =~ /\.php.*$/i or $attr_value =~ /\.cgi.*$/i)
- ){
- $attr_value =~ s/^(.+)#.*$/$1/;
- next if(defined $seen{$attr_value});
- my @heads = LWP::Simple::head($attr_value);
- if(@heads) {
- $seen{$attr_value}++;
- my @date = $heads[2] ? gmtime($heads[2]) : gmtime(time);
- $mod_time{$attr_value} = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $date[5]+1900, $date[4]+1, @date[3,2,1,0]);
- }
- }
- }
- }
- for (sort keys %seen) {
- my $mod = $mod_time{$_};
- s/^(.+\.cgi).*$/$1/i;
- s/^(.+\.php).*$/$1/i;
- if(defined $out{$_}) {
- next;
- } else {
- $out{$_} = 'true';
- print_xml($_,$mod);
- linker($_);
- }
- }
- }
- sub print_xml_head {
- my %in_url = @_;
- my @date = gmtime(time);
- my $mod_time = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $date[5]+1900, $date[4]+1, @date[3,2,1,0]);
- print <<XML;
- <?xml version="1.0" encoding="UTF-8"?>
- <urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
- http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">\n
- <url>
- <loc>$top_url</loc>
- <lastmod>$mod_time</lastmod>
- <changefreq>$freq</changefreq>
- <priority>$priority</priority>
- </url>\n
- XML
- }
- sub print_xml {
- print qq(<url>\n<loc>$_[0]</loc>\n<lastmod>$_[1]</lastmod>\n</url>\n);
- }
- sub print_xml_foot {
- print qq(\n</urlset>\n);
- }
続きを読む : "GoogleSitemapsジェネレータ"
Google Sitemaps ジェネレーターを作るにあたり、ネットワークから
サイト内のリンクをたどり、同一サイト内のURLを抽出するスクリプトを作ってみた
Code: download
- use LWP::Simple qw(get head);
- use HTML::LinkExtor;
- use strict;
- my(%seen,%mod_time,%out,$site,$top_url);
- $top_url = 'http://sieg.xeong.com/';
- $top_url = "http://$top_url" unless $top_url =~ /^https?\b/;
- ($site = $top_url) =~ s/^(http:\/\/.+\/).*$/$1/;
- $site .= "/" unless ($site =~ /\/$/);
- linker($top_url);
- sub linker {
- my $base_url = shift;
- my $parser = HTML::LinkExtor->new(undef, $base_url);
- $parser->parse(get($base_url))->eof;
- my @links = $parser->links;
- for my $linkarray (@links) {
- my @element = @$linkarray;
- my $elt_type = shift @element;
- while(@element) {
- my ($attr_name, $attr_value) = splice(@element, 0,2);
- if( $attr_name eq "href" && $attr_value->scheme =~ /\b(https?)\b/ && $attr_value =~ /^$site/){
- # && ($attr_value =~ /\.xml?$/i or $attr_value =~ /\.s?html?$/i or $attr_value =~ /\.php.*$/i or $attr_value =~ /\.cgi.*$/i)){
- $attr_value =~ s/^(.+)#.*$/$1/;
- next if(defined $seen{$attr_value});
- my @heads = LWP::Simple::head($attr_value);
- if(@heads) {
- $seen{$attr_value}++;
- my @date = $heads[2] ? gmtime($heads[2]) : gmtime(time);
- $mod_time{$attr_value} = sprintf("%04d-%02d-%02dT%02d:%02d:%02dZ", $date[5]+1900, $date[4]+1, @date[3,2,1,0]);
- }
- }
- }
- }
- for (sort keys %seen) {
- my $mod = $mod_time{$_};
- # s/^(.+\.cgi).*$/$1/i;
- # s/^(.+\.php).*$/$1/i;
- if(defined $out{$_}) {
- next;
- } else {
- $out{$_} = 'true';
- print qq($_ - $mod\n);
- linker($_);
- }
- }
- }
続きを読む : "サイト探索"
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
| 31 |