在重置之前从Google论坛下载帖子

时间:2012-08-21 20:08:30

标签: python screen-scraping google-groups

我想重置我的一个小组(课堂讨论),但我想保留讨论以供参考。没有多少帖子(可能是50个),我可以手工完成,但有没有办法通过谷歌应用程序脚本或python做到这一点?

我发现了一些可能性,但是我不熟悉的语言(尽管我可以翻译):

此链接:http://saturnboy.com/2010/03/scraping-google-groups/

这个Perl代码:

#!/usr/bin/perl
# groups2csv.pl
# Google Groups results exported to CSV suitable for import into Excel.
# Usage: perl groups2csv.pl < groups.html > groups.csv

# The CSV Header.
print qq{"title","url","group","date","author","number of articles"\n};

# The base URL for Google Groups.
my $url = "http://groups.google.com";

# Rake in those results.
my($results) = (join '', <>);

# Perform a regular expression match to glean individual results.
while ( $results =~ m!<a href=(/groups[^\>]+?rnum=[0-9]+)>(.+?)</a>.*?
<br>(.+?)<br>.*?<a href="?/groups.+?class=a>(.+?)</a> - (.+?) by 
(.+?)\s+.*?\(([0-9]+) article!mgis ) {
    my($path, $title, $snippet, $group, $date, $author, $articles) =
        ($1||'',$2||'',$3||'',$4||'',$5||'',$6||'',$7||'');
    $title =~ s!"!""!g; # double escape " marks
    $title =~ s!<.+?>!!g; # drop all HTML tags
    print qq{"$title","$url$path","$group","$date","$author","$articles"\n\n};
}

1 个答案:

答案 0 :(得分:0)

查看此HTTrack utility及此webapps question中提及的forum discussion

注意我假设您实际上并不想筛选和处理数据,而只是有一份讨论副本供将来参考。

编辑:如果你真的想要屏幕刮,你也可以这样做,但写一个脚本来做这件事可能是一个重要的时间下沉。屏幕抓取更多的是从html文档中提取特定的数据而不是抓取整个html文档。您可能需要屏幕搜索的一个示例是,如果您正在查看危险的网站,并希望获取个别问题,他们的积分值,谁正确回答,他们发生的游戏等等,以便插入数据库。