如何保存 phpBB-3 站点?管理员去世了,无法进行SQL转储:(到目前为止,我有这个,但没有获得帖子的内容



我想保留几年前的网站帖子,但在网站管理员去世后没有人可以访问数据库。 :( 有没有更好的方法可以做到这一点?

这就是我目前所拥有的。它是保存主题和什么,但不是内容。我想下载每个类别下的帖子,并使用vanilla,myBB,flarum或phpBB(尚未决定哪个)将它们导入SQL。输出:

在 ./fetch-phpbb.pl 第 56 行使用未初始化的值 $posts_in_topic 替换 (s///)。

在 ./fetch-phpbb.pl 第 66 行的串联 (.) 或字符串中使用未初始化的值$year。

在连接 (.) 中使用未初始化的值$month或 ./fetch-phpbb.pl 第 66 行的字符串。

在 ./fetch-phpbb.pl 第 66 行的串联 (.) 或字符串中使用未初始化的值$day。

在 ./fetch-phpbb.pl 第 71 行打印的宽字符。

在串联 (.) 中使用未初始化的值 $posts_in_topic 或

./fetch-phpbb.pl 第 73 行处的字符串。

保存的网站名称主题-00001-页面-000----

General_discussion_Expecting_Rain.html ( 帖子总数

)在数字 gt (>) 中使用未初始化的值 $posts_in_topic 在

./fetch-phpbb.pl 第 75 行。

使用未初始化的值 $posts_in_topic 替换 (s///) at

./fetch-phpbb.pl 第 56 行。

在串联 (.) 中使用未初始化的值$year或字符串

./fetch-phpbb.pl 第 66 行。

在串联 (.) 中使用未初始化的值$month或字符串

./fetch-phpbb.pl 第 66 行。

在串联 (.) 中使用未初始化的值$day或字符串

./fetch-phpbb.pl 第 66 行。

在 ./fetch-phpbb.pl 第 71 行打印的宽字符。

#!/usr/bin/perl
use strict;
use warnings;
require LWP::UserAgent;
use POSIX qw/ceil/;
my $ua = LWP::UserAgent->new(agent => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:10.0.2) Gecko/20100101 Firefox/10.0.2');
$ua->timeout(10);
my $sid = 'efba981e5f1d54639b2bb67d8adf2a11';
$ua->default_header('Host' => 'expectingrain.com');
$ua->default_header('Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8');
$ua->default_header('Accept-Language' => 'en-us,en;q=0.5');
$ua->default_header('Accept-Encoding' => 'gzip, deflate');
$ua->default_header('DNT' => '1');
$ua->default_header('Connection' => 'keep-alive');
$ua->default_header('Cache-Control' => 'max-age=0');
#$ua->default_header();
my $max_topic_id = 20000;
my $posts_per_topic_page = 30;
my $topics_per_forum_page = 50;
my $output_file_name_base = 'sitename-';
my $base_url = 'https://expectingrain.com/discussions/viewforum.php?f=6';
my %status = ();
for (my $i = 1; $i <= $max_topic_id; $i++) {
my $posts_in_topic = 0;
my $url = $base_url . '?sid=' .$sid . '&t='.$i;
my $response = $ua->get($url );
if ($response->is_success) {
my $page_content = $response->decoded_content;
# [ 621 posts ]
if ($page_content =~ /topic does not exist/) {
print STDERR "$url: Topic $i does not existn";
$status{'invalid topic'}++;
} elsif ($page_content =~ /not authorised/) {
print STDERR "$url: Not authorizedn";
$status{'unauthorized'}++;
} elsif ($page_content =~ /requires you to be registered and logged in/) {
print STDERR "$url: Login prompt.n";
$status{'login message'}++;
} elsif ($page_content =~ /forum you selected does not exist/) {
print STDERR "$url: Forum does not existn";
$status{'forum dne'}++;
} else {
$posts_in_topic = ($page_content =~ / ([d,]+) post(s?) /)[0];
$posts_in_topic =~ s/,//;
$status{'valid post'}++;
#                        print "Topic #$i contains $posts_in_topic postsn";
my $title = ($page_content =~ /<title>(.+)</title>/)[0];
$title =~ s/[^ws]+//g;
$title =~ s/s+/_/g;
# <td class="postbottom" align="center">Sat Nov 01, 2008 9:00 pm</td>
my ($crap, $wd, $month, $day, $year) = ($page_content =~ />((w{3}) (w{3}) (d{2}), (d{4})) d+:d{2} ..</td/);
my $date_str = "$year-$month-$day";
my $output_filename = sprintf("$output_file_name_base"."topic-%05d-page-000-$date_str-$title.html",$i);
open(FILE, ">$output_filename") or die $!;
print FILE $page_content;
close(FILE);
print "Saved $output_filename ($posts_in_topic total posts)n";
if ($posts_in_topic > $posts_per_topic_page) {
my $total_pages = ceil($posts_in_topic / $posts_per_topic_page);
for (my $j = 1; $j < $total_pages; $j++) {
my $start = $j * $posts_per_topic_page;
my $page_url = $url . '&start='.$start;
my $page_filename = sprintf("$output_file_name_base".'topic-%05d-page-%03d.html',$i, $j);
my $page_response = $ua->get($page_url, ':content_file' => $page_filename);
if ($page_response->is_success) {
print "Saved Content File $page_filenamen";
} else {
print STDERR "Error fetching $page_url: {$response->status_line}n";
}
}
}
#       print $page_content;
}
} else {
print STDERR "Error fetching $url: {$response->status_line}n";
$status{'error:'.$response->status_line}++;
}
}

因此,在第一个请求中,程序将获得以下 URL:

  • https://expectingrain.com/discussions/viewforum.php?f=6?sid=efba981e5f1d54639b2bb67d8adf2a11&t=1

这将返回一个 200 响应代码,并且内容不包含代码查找的任何字符串,因此您最终会进入if ($page_content =~ /.../)代码的else块。这从以下几行开始:

$posts_in_topic = ($page_content =~ / ([d,]+) post(s?) /)[0];
$posts_in_topic =~ s/,//;

这会在您的页面内容中搜索由许多数字和逗号组成的字符串,后跟一个空格、单词"post"和一个可选的"s"。然后,它会从找到的字符串中删除第一个逗号。这是第二行(删除逗号的那行,给你错误说:

在 ./fetch-phpbb.pl 第 56 行使用未初始化的值 $posts_in_topic 替换 (s///)。

但是,如果您查看该页面,您会发现没有由数字(包括逗号)后跟"post"或"posts"组成的字符串。但是,页面顶部附近有一个字符串,上面写着"27559 个主题"。

您的下一个错误是:

在连接 (.) 中使用未初始化的值 $year 或在 ./fetch-phpbb.pl 行 66.
在连接 (.) 中使用未初始化的值$day或在 ./fetch-phpbb.pl 第 66 行使用字符串。

而且,如果你看一下代码,你会看到一段类似的代码:

my ($crap, $wd, $month, $day, $year) = ($page_content =~ />((w{3}) (w{3}) (d{2}), (d{4})) d+:d{2} ..</td/);
my $date_str = "$year-$month-$day";

同样,我们尝试匹配数据并将其存储在变量中。我们正在寻找三个字母数字(w{3}),另外三个字母数字(再次w{3}),两位数(d{2})和四位数字(d{4}),并将它们存储在变量中$wd工作日?),$month$day$year。所有这些都让我觉得我们正在寻找看起来像"2021 年 12 月 27 日星期一"的日期。而且,同样,查看页面时,该页面上没有该格式的日期。所有日期都像"2021 年 12 月 27 日星期一"。

我不确定你从哪里得到这段代码,但在我看来,它似乎是为不同版本的 phpBB 编写的 - 它以与代码预期不同的方式格式化页面上的数据。

您可以通过更改代码来解决这些问题。

$posts_in_topic = ($page_content =~ / ([d,]+) post(s?) /)[0];

应该变成:

$posts_in_topic = ($page_content =~ /([d,]+) topic(s?)/)[0];

my ($crap, $wd, $month, $day, $year) = ($page_content =~ />((w{3}) (w{3}) (d{2}), (d{4})) d+:d{2} ..</td/);

应该变成这样:

my ($wd, $month, $day, $year) = ($page_content =~ />(w{3}) (w{3,9}) (d{2})ww, (d{4}) d+:d{2} ..</td/);

(实际上,最后一个不起作用,因为页面上的 HTML 也不同 - 我没有时间进一步调查。

因此,总而言之,该程序不是为您的网站制作的。你也许可以破解这个,或者你可能会找到一个可用于你的phpBB版本。

但我真的认为最好的选择是与网络托管公司取得联系,解释情况,看看他们如何为您提供帮助。老实说,根据我的经验,大多数挪威人的英语比大多数英国人说得更好:-)

相关内容

最新更新