http://xiaoqu.koubei.com/community/browse_listing_20.html");
PostSection[] section = GS.GetSection(html);
foreach (object obj in section) { string S1 = ((PostSection)obj).Name;int S2 = ((PostSection)obj).Option;
html = GS.GetSubSection(S2);}"/>
问题描述:
public class City
{ static string CurrentURL; public string GetHtml(string Url)
{ CurrentURL = Url; string html = RealPage.Get(Url); return html;}
public PostSection[] GetSection(string html)
{ ProvideRegex PR = new ProvideRegex();
Regex ReList = new Regex(PR.SectionList); Match MCList = ReList.Match(html);
string StrResults = MCList.Groups[1].Value.Trim();Regex ReItem = new Regex(PR.SectionItem);
MatchCollection McItem = ReItem.Matches(StrResults);int Count = McItem.Count;
PostSection[] section = new PostSection[Count]; string s = section.GetType().ToString();
for (int i = 0; i < Count; i++)
{
section[i] = new PostSection();
Match MItem = McItem[i];
section[i].Option = Convert.ToInt32(Regex.Replace(MItem.Groups[1].Value.Trim(), @"[^0-9]", ""));
section[i].Name = MItem.Groups[2].Value.Trim();
} return section;}
public string GetSubSection(int Section)
{
string html = PostData(Section);return html;
}
private string PostData(int section)
{
string html = "";
byte[] postData = Encoding.Default.GetBytes("areaid=" + section + "&garden=");
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(CurrentURL);
Request.Method = "POST"; Request.ContentLength = postData.Length;
Request.ContentType = "multipart/form-data";CookieContainer cc = new CookieContainer();
using (Stream sm = Request.GetRequestStream())
{sm.Write(postData, 0, postData.Length);sm.Close();}
Request.CookieContainer = cc;
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
Response.GetResponseStream();
Response.Cookies = cc.GetCookies(Request.RequestUri);
using (Stream sm = Request.GetResponse().GetResponseStream())
{ using (StreamReader sr = new StreamReader(sm,Encoding.Default))
{ html = sr.ReadToEnd();sr.Close(); sm.Close(); }} return html; } }
class ProvideRegex
{
public string SectionList = @"name=""areaid"">(.*?)</select>";
public string SectionItem = @"<option.*?value=(.*?)>(.*?)</";
}
public class SectionData { public string name; public string URL;}
public class PostSection
{
public string Name; public int Option;
}
调用代码: City GS = new City();baidu提问限制3千字节,因此删除了一些个try catch语句.格式也调整了下.请大家帮忙仔细看看!
string html = GS.GetHtml("http://xiaoqu.koubei.com/community/browse_listing_20.html");
PostSection[] section = GS.GetSection(html);
foreach (object obj in section) { string S1 = ((PostSection)obj).Name;int S2 = ((PostSection)obj).Option;
html = GS.GetSubSection(S2);}
问题解答:
你用的是什么环境?应该有控件可以用的吧?
比如你使用VS2005,那就可以使用LinkLabel控件,双击,会出现linkLabel1_LinkClicked事件
代码如下:
private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
try
{
VisitLink();
}
catch (Exception ex )
{
MessageBox.Show("Unable to open link that was clicked.");
}
}
private void VisitLink()
{
// 让linkLabel1的LinkVisited属性为true.
linkLabel1.LinkVisited = true;
//调用Process.Start 方法去打开默认浏览器
//设置一个URL:
System.Diagnostics.Process.Start("http://xiaoqu.koubei.com/community/browse_listing_20.html");
}
真乱……
也只有你自己才看得懂了……
代码登录网站?
属于外部提交!