1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

小説家になろうの活動報告欄でアンケート取ってる人が居たので集計してみた話

Last updated at Posted at 2019-11-09

#ざっくり手順
1.コメントをごっそりhtmlとして保存する
2.コメント本文だけを抜き出す
3.集計

#1.コメントをごっそりhtmlとして保存する
url一覧を作ってチョメチョメしてwgetでDL
具体的には

download.sh
#!/bin/bash

cat urllist.txt | perl -lne 'for($i=1;$i<=10;$i++){print $_."index.php?p=".$i}' > urllist2.txt
# wget -i urllist2.txt
# アクセス過剰で503で死んだので適当にスリープ
while read line
do
  wget $line
  sleep 10
done < urllist2.txt

urllist.txtには改行区切りで投票やってる活動報告個別ページurlを記載
作業用にurllist2.txtが出力される。
index.phpp=[0-9]なファイル名で結果が出力されるので適当にディレクトリに纏める。

#2.コメント本文だけを抜き出す
タグからコメント部分だけをブチ抜く。
コメント部分の開始終了タグが分かりやすかったのでその辺を目印に適当に

getcomment.pl
opendir (DIR,"resultfiles");
@file = readdir(DIR);
closedir(DIR);
open OUT,">./results.txt";

foreach $file(@file){;
	open IN,"./resultfiles/$file";
	$flg = 0;
	while ($line = <IN>){
		print "$flg";
		if($line =~ /<div id="blog_comment">/){
			$flg = 1;
		}if($line =~ /<\!\-\-blog_comment\-\->/){
			$flg = 0;
		}
		if($flg == 1){
			$line =~ s/\<.*?\>//g;
			print OUT $line;
		}
	}
}

3.集計
sortしてuniq

cat results.txt|sort|uniq -c > allresult.txt

表記揺れとかアホほどあったのでそこは適当にガシガシ編集する感じで。
投票にgoogle formとかのアンケ機能素直に使ったほうが集計作業は楽だったんじゃないかと思いました。まる

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?