取网页内字段值

using System;
using System.IO;
using System.Net;
using System.Collections.Generic;
using System.Text;

namespace Get51Job
{
    class Get51job
    {
        public string Get1stPage()
        {
            Uri uri = new Uri("http://search.51job.com/jobsearch/search_result.php");
            HttpWebRequest wrq = WebRequest.Create(uri) as HttpWebRequest;

            wrq.Referer = "http://www.51job.com/default-area.php?area=0100";
            wrq.Method = "POST";

            string postdata = "jobarea=0100&funtype_big=0100&funtype=0100&industrytype=01&issuedate=2&stype=0&postchannel=0000&postfrom=0100&keyword=.net&keywordtype=1&x=34&y=12";

            byte[] buf = Encoding.GetEncoding("gb2312").GetBytes(postdata);
            wrq.ContentType = "application/x-www-form-urlencoded";
            wrq.ContentLength = buf.Length;

            Stream stream = wrq.GetRequestStream();
            stream.Write(buf, 0, buf.Length);
            stream.Close();

            wrq.CookieContainer = new CookieContainer();

            wrq.CookieContainer.Add(uri,new Cookie("guid","12217044405506400026"));
            wrq.CookieContainer.Add(uri, new Cookie("51job", "cenglish%3D0"));
            wrq.CookieContainer.Add(uri, new Cookie("ord_list_field", "0%7C1"));
            wrq.CookieContainer.Add(uri, new Cookie("last_search", "0100%7E%602%7E%6099%7E%6099%7E%600100%7E%600100%7E%6001%7E%6099%7E%6099%7E%6099%7E%60.net%7E%601%7E%601%7E%601221711222"));

            HttpWebResponse wrp = wrq.GetResponse() as HttpWebResponse;
            Stream s = wrp.GetResponseStream();
            StreamReader sr = new StreamReader(s, Encoding.GetEncoding("gb2312"));
            string page = sr.ReadToEnd();
            sr.Close();
            s.Close();

            return page;

        }

    }
    class Test
    {
        static void Main()
        {
            Get51job _51job = new Get51job();
            string page = _51job.Get1stPage();
        }
    }
}

posted @ 2008-09-18 15:02  小人物.net  阅读(372)  评论(0)    收藏  举报