2ちゃんねる2GETスクリプトの改良おねがいします

このエントリーをはてなブックマークに追加
1デフォルトの名無しさん
Cookieの仕様が変わってしまった為、現在の2chでは使えません。
どなたか使えるように改良してくださいお願いします。

スクリーンショット
http://b.x0.to/src/up0658.jpg

ソース
http://b.x0.to/src/up0663.rar
2デフォルトの名無しさん:2006/10/23(月) 06:20:53
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using System.Threading;

namespace GetDat
{
/// <summary>
/// Class1 の概要の説明です。
/// </summary>
class Class1
{
/// <summary>
/// アプリケーションのメイン エントリ ポイントです。
/// </summary>
///

private static CookieContainer cContainer = new CookieContainer();

struct ThreadInfo
{
public string dat,subject;
public int no,res;
}

[STAThread]
static void Main(string[] args)
3デフォルトの名無しさん:2006/10/23(月) 06:21:25
{
Post("0");
int cwrite=0,ctry=0;
while(true)
{
Console.Write(">>> GET\n\n");
ArrayList tl = GetThreadList();
foreach(ThreadInfo d in tl)
{
if(d.res == 1 && d.no <= 100)
{
Console.Write("No."+ d.no +" "+ d.dat +"\n");
Console.Write(d.subject + "\n");
Console.Write("(" + d.res + ")\n\n");
int dd = d.dat.IndexOf(".");
string d2 = d.dat.Substring(0,dd);
Console.Write("(" + d2 + ")\n\n");
Post(d2);
cwrite++;
Console.Write("::: SLEEP :::\n\n");
Thread.Sleep(32*1000);
break;
}
}
Console.Write("<<< DONE\n\n");
Thread.Sleep(1000);
ctry++;
Console.Write("state try : "+ ctry + " write : " + cwrite + "\n\n");
}
}
4デフォルトの名無しさん:2006/10/23(月) 06:22:06
public static ArrayList GetThreadList()
{
HttpWebRequest request
= (HttpWebRequest)HttpWebRequest.Create("http://news20.2ch.net/news/subject.txt");
request.UserAgent = "monazilla/1.00 (getDat/0.01)";
WebResponse response = request.GetResponse();

Encoding encode = Encoding.GetEncoding("Shift_JIS");
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream,encode);

ArrayList tlist = new ArrayList();

string dat,subject;
int res;
string line;
int n=1,idxSep,rb,re;
while((line = reader.ReadLine()) != null)
{
5デフォルトの名無しさん:2006/10/23(月) 06:22:38
idxSep = line.IndexOf("<>");
dat= line.Substring(0,idxSep);
subject= line.Substring(idxSep+2);
rb = subject.LastIndexOf("(");
re = subject.LastIndexOf(")");
res = int.Parse(subject.Substring(rb+1,re-rb-1));
subject = subject.Substring(0,rb);

/*Console.Write("No."+ n +" "+ dat +"\n");
Console.Write(subject + "\n");
Console.Write("(" + res + ")\n\n");*/

ThreadInfo ti;
ti.no= n;
ti.dat= dat;
ti.subject= subject;
ti.res= res;

tlist.Add(ti);
6デフォルトの名無しさん:2006/10/23(月) 06:23:11
n++;
}

return tlist;
}

/*public static void GetThreadList()
{
//HttpWebRequest request
//= (HttpWebRequest)HttpWebRequest.Create("http://ex11.2ch.net/news4vip/dat/1120420655.dat");
HttpWebRequest request
= (HttpWebRequest)HttpWebRequest.Create("http://news20.2ch.net/news/subject.txt");
request.UserAgent = "monazilla/1.00 (getDat/0.01)";
WebResponse response = request.GetResponse();

Encoding encode = Encoding.GetEncoding("Shift_JIS");
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream,encode);
Console.Write(reader.ReadToEnd());
}*/

public static void Post(string datcode)
{
7デフォルトの名無しさん:2006/10/23(月) 06:25:55
Encoding sjis_enc = Encoding.GetEncoding("Shift_JIS");

string postData = "submit="+HttpUtility.UrlEncode("書き込む",sjis_enc)+"&"
+"subject="+HttpUtility.UrlEncode("",sjis_enc)+"&"
+"FROM="+HttpUtility.UrlEncode("乳酸菌とってるぅ?",sjis_enc)+"&"
+"mail="+HttpUtility.UrlEncode("乳酸菌とってるぅ?",sjis_enc)+"&"
+"MESSAGE="+HttpUtility.UrlEncode(">>1\n乳酸菌とってるぅ?",sjis_enc)+"&"
+"bbs="+"news"+"&"
+"key="+ datcode +"&"
+"time="+"1104688508";
Encoding ascii = new ASCIIEncoding();
byte[] bytedata = sjis_enc.GetBytes(postData);

HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://news20.2ch.net/test/bbs.cgi");
8デフォルトの名無しさん:2006/10/23(月) 06:26:31
request.CookieContainer = new System.Net.CookieContainer();
request.CookieContainer.Add(cContainer.GetCookies(request.RequestUri));

request.Method="POST";
request.ContentType="application/x-www-form-urlencoded";
request.UserAgent = "monazilla/1.00 (hamipanX/0.01)";
request.ContentLength = bytedata.Length;
request.Referer = "http://news20.2ch.net/test/read.cgi/news/1117035541/";
Stream reqstream = request.GetRequestStream();
reqstream.Write(bytedata,0,bytedata.Length);
reqstream.Close();

WebResponse response = request.GetResponse();
Stream resstream = response.GetResponseStream();
StreamReader reader = new StreamReader(resstream,sjis_enc);
Console.Write(reader.ReadToEnd());

CookieCollection cookies =
request.CookieContainer.GetCookies(request.RequestUri);
foreach (System.Net.Cookie cook in cookies)
Console.WriteLine("{0}={1}", cook.Name, cook.Value);
cContainer.Add(cookies);
resstream.Close();
9デフォルトの名無しさん
もっとましなもん作れよ