程序
下一秒就爱你吧
全部回复
仅看楼主
level 1
quicker1 楼主
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Linq;using System.Text;using System.Web;using System.Net;using System.Runtime.InteropServices;using System.Threading;using System.IO;namespace test2{    class Program    {        //百度网页的编码格式为GB2312        static Encoding encoding = Encoding.GetEncoding("GB2312");        static String cookieStr;//保存cookie字符串用的        static Thread[] threadGrp;        static int thread_num =15;//线程数目        static int indexer = 0;   //代理索引        static int urlIndex = 0;  //需要访问的链接的索引                    static int normal_sleep =5000;//每次访问之后线程休眠的时间,刷得太快会被封ip        static int failed_sleep =0;        static int counter = 0;        static int majorCounter=0;//记录总共访问了多少次        static bool ifUseProxy = true;//是否启用代理,用了代理访问速度会变慢,需要注意的是,baidu能够认出普通的代理        static void Main(string[] args)        {            //从文件中获取上一次的session cookie或者重新获取session cookie            FileStream fs = new FileStream("C:\\ss.txt",FileMode.OpenOrCreate);            if (fs.Length>0)            {                //如果文件是空或者没有文件,则重新获取session cookie                StreamReader sr = new StreamReader(fs);                cookieStr = sr.ReadToEnd();                //将新的cookie写到文件中,这样做的目的是不必每次启动程序就去登录获取cookie,次数多了之后,会需要验证码
2008年10月02日 15点10分 1
level 1
quicker1 楼主
                //程序还没有实现验证码识别                Console.WriteLine("Get Session from file:\n" + cookieStr);                sr.Close();                fs.Close();            }            else            {                //从文件中直接获取上次的cookie                StreamWriter sw = new StreamWriter(fs);                cookieStr = getSession();                Console.WriteLine("Get new Session:\n" + cookieStr);                sw.Write(cookieStr);                sw.Close();                fs.Close();            }            //线程的初始化            threadGrp = new Thread[thread_num];            for (int i = 0; i < thread_num; i++)            {                threadGrp[i] = new Thread(new ThreadStart(ThreadProc));                threadGrp[i].Start();            }            //线程一直运行            for (int i = 0; i < thread_num; i++)            {                threadGrp[i].Join(Timeout.Infinite);            }
2008年10月02日 15点10分 2
level 1
quicker1 楼主
                resp = (HttpWebResponse)hwr.GetResponse();                if (resp.StatusCode == HttpStatusCode.OK)                {                    return "ok";                }                else return "error";            }            catch (Exception ex)            {                throw (ex);            }            finally            {                if (resp != null) resp.Close();            }        }        static String getSession()        {            //链接到登录链接获取会话cookie                                                 //下面这里改成你的密码            String loginUrl = "http://passport.baidu.com/?login&username=quicker1&password=***&mem_pass=1";            HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(loginUrl);            CookieContainer ck = new CookieContainer();            hwr.CookieContainer = ck;            HttpWebResponse resp = null;            try            {                resp = (HttpWebResponse)hwr.GetResponse();
2008年10月02日 15点10分 5
1