Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require 'open-uri'
open("https://futaba-only.net/list01.html"){|l|
$data=l.read.force_encoding("UTF-8")
}
c=Array.new(7).map{Array.new}
7.times{|i|
re=Regexp.compile(%Q(<td class="clist2-#{i+1}">(.*?)<\/td>))
c[i]<< $data.scan(re)
}
#c={:0->企画名orサークル名,:1->ハンドル,:2->板,:3->URL_1,:4->URL_2,:5->区分,:6->配置(サークル番号)}
7.times{|i|
c[i].flatten!
}
c[3].map!{|url|
url=url=="<br />"? "(null)":url.scan(/\"(http.*?)\"/)[0]
if !url.nil?&&!(tw=url[0].scan(/http[s]{,1}:\/\/twitter\.com\/(.*)/)[0]).nil?
url="ヒ=>#{tw}"
elsif !url.nil?&&!(pic=url[0].scan(/http[s]{,1}:\/\/www\.pixiv\.net\/member\.php\?id=(.*)/)[0]).nil?
url="渋=>#{pic}"
elsif !url.nil?
url=url
else
url="(null)"
end
}
c[4].map!{|url|
url=url=="<br />"? "(null)":url.scan(/\"(http.*?)\"/)[0]
if !url.nil?&&!(tw=url[0].scan(/http[s]{,1}:\/\/twitter\.com\/(.*)/)[0]).nil?
url="ヒ=>#{tw}"
elsif !url.nil?&&!(pic=url[0].scan(/http[s]{,1}:\/\/www\.pixiv\.net\/member\.php\?id=(.*)/)[0]).nil?
url="渋=>#{pic}"
elsif !url.nil?
url=url
else
url="(null)"
end
}
c[2].map!{|s|
s.sub(/二次元裏/,"")
}
c[3].flatten!;c[4].flatten!
7.times{|i|
c[i].shift
}
9.times{|i|
c[5].unshift nil;c[6].unshift "(null)"
}
open("circul.csv","w") do |cs|
cs.puts "サークル番号,サークル名,ハンドル,板,URL_1,URL_2"
c[6].zip(c[0],c[1],c[2],c[3],c[4],c[5],c[6]).each{|s|
cs.puts s.join(",")
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment