|
楼主 |
发表于 2013-9-18 21:19:58
|
显示全部楼层
ParameterizedThreadStart startDownload = new ParameterizedThreadStart(Dntq);//线程起始设置:即每个线程都执行DownLoad()
downloadThread = new Thread[theMatches.Count];//为线程申请资源,确定线程总数
foreach (Match thematch in theMatches)
{
if (thematch.Length != 0)
{
rwjdt.Value += 90 / theMatches.Count;
IpAndPort aa = new IpAndPort();
//for (int i = 0; i < n; i++)//开启指定数量的线程数
//{
//currentline=kk;
//sjo =
downloadThread[kk] = new Thread(startDownload);//指定线程起始设置
aa.sjk = thematch.Value.ToString();
aa.ls = kk;
downloadThread[kk].Start((object)aa);//逐个开启线程
if (kk<2)
{
kk += 1;
}
//Thread.Sleep(500);//当前线程(你所谓的子线程)休息50毫秒
//}
//Thread thr = new Thread(a);
//IpAndPort aa = new IpAndPort();
//aa.sjk = "123.123.123.123";
//aa.ls = 1;
//thr.Start((object)aa);
}
}
this.richTextBox1.Text += "\r\n" + "提取完毕!";
rwjdt.Value = 100;
}
else
this.richTextBox1.Text += "\r\n文件下载失败!";
#endregion
}
struct IpAndPort
{
public string sjk;
public int ls;
}
private void Dntq(object aa)
{
Thread.Sleep(800);
IpAndPort sjxl = (IpAndPort)aa;
//m_TaoItem m_TaoItem1 = new m_TaoItem();
//m_TaoItem1.CookieCollection = m_TaoItem.CookieCollection;
//string resultt = "";
//resultt += "\r\n" + thematch.Value.ToString();
Match TitleMatch = Regex.Match(sjxl.sjk, ":([^<]*)</label></span>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Match TitleMatch1 = Regex.Match(sjxl.sjk, "userID=([^<]*)\" target=", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Match TitleMatch2 = Regex.Match(sjxl.sjk, "查看宝贝详情\" target=\"_blank\">([^<]*)</a><br />", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Match TitleMatch3 = Regex.Match(sjxl.sjk, "<td class=\"num\" title=\"([^<]*)\">", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Match TitleMatch4 = Regex.Match(sjxl.sjk, "<strong class=\"J_OrderPrice\">([^<]*)</strong>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
ListViewItem lvItem1 = new ListViewItem();
lvItem1.Tag = "";
lvItem1.Text = " ";
string[] strRoom2 = { " ", " ", " ", " ", " ", " ", " ", " " };
lvItem1.SubItems.AddRange(strRoom2);
ListView1.Items.Add(lvItem1);
//ListView1.Items.Add(Convert.ToString(currentline + 1));
ListView1.Items[sjxl.ls].SubItems[0].Text = Convert.ToString(sjxl.ls + 1);
ListView1.Items[sjxl.ls].SubItems[1].Text = TitleMatch.Groups[1].Value;
ListView1.Items[sjxl.ls].SubItems[2].Text = TitleMatch1.Groups[1].Value;
ListView1.Items[sjxl.ls].SubItems[3].Text = TitleMatch2.Groups[1].Value;
ListView1.Items[sjxl.ls].SubItems[4].Text = TitleMatch3.Groups[1].Value;
ListView1.Items[sjxl.ls].SubItems[5].Text = TitleMatch4.Groups[1].Value;
#region 提取订单文件
// HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://trade.taobao.com/trade/detail/trade_item_detail.htm?bizOrderId=" + TitleMatch.Groups[1].Value));
m_TaoItem.Method = "get";
m_TaoItem.URL = "http://trade.taobao.com/trade/detail/trade_item_detail.htm?bizOrderId=" + TitleMatch.Groups[1].Value;
//string.Format("http://u.alimama.com/union/newreport/taobaokeDetail.do?toPage=1&perPageSize=20&startTime={0}&endTime={1}&DownloadID=DOWNLOAD_REPORT_INCOME_NEW&payStatus=&total=100&queryType=1", DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd"), DateTime.Now.ToString("yyyy-MM-dd"));
m_TaoItem.ResultType = ResultType.Byte; //这里注意是以字节方式获取结果
m_TaoItem.Allowautoredirect = true; //这里一定要为真
m_TaoItem.Accept = "text/html, application/xhtml+xml, */*";
//m_TaoItem.Referer = "http://u.alimama.com/union/newreport/taobaokeDetail.htm?spm=0.0.0.0.LloOpJ";
m_TaoItem.Header["Accept-Encoding"] = "gzip, deflate";
HttpResult result = m_Http.GetHtml(m_TaoItem);
//收货地址:</th><td>
//Match TitleMatch9 = Regex.Match(resultp.Html.Replace("\r\n", ""), "class=\"simple-list logistics-info\">([^<]*)</td>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Match TitleMatch5 = Regex.Match(result.Html.Replace("\r\n", ""), "收货地址:</th>(.*?)</td>", RegexOptions.IgnoreCase | RegexOptions.Multiline);
ListView1.Items[sjxl.ls].SubItems[6].Text = TitleMatch5.Groups[1].Value.Replace("<td>", "").Replace(" ", "");
//this.richTextBox1.Text += "\r\n" + ListView1.Items[sjxl.ls].SubItems[1].Text.ToString() + sjxl.ls.ToString();
ListView1.Items[sjxl.ls].SubItems[7].Text = "提取完毕" + sjxl.ls.ToString();
// xLog("线程:" + sjxl.ls + "执行完成!");
downloadThread[sjxl.ls].Abort();
#endregion
} |
|