public List <T> GetBillList <T>(DateTime startDate, string cookieStr) { JsonSerializer serializer = JsonSerializer.CreateInstance(); string dateTimeStr = serializer.Serialize(startDate).Substring(9).TrimEnd(')'); string data = "auctionType=0&close=0&pageNum={0}&pageSize={1}&queryMore=true&rxAuditFlag=0&rxHasSendFlag=0&rxOldFlag=0&rxSendFlag=0&rxSuccessflag=0&tradeTag=0&useCheckcode=false&useOrderInfo=false&errorCheckcode=false&action=itemlist%2FSoldQueryAction&dateBegin="; data += dateTimeStr + "&prePageNo={2}&buyerNick=&dateEnd=0&logisticsService=&orderStatus=&queryOrder=desc&rateStatus=&refund=&sellerNick=&tabCode=latest3Months"; //string data = "auctionType=0&close=0&pageNum={0}&pageSize={1}&queryMore=false&rxAuditFlag=0&rxHasSendFlag=0&rxOldFlag=0&rxSendFlag=0&rxSuccessflag=0&tradeTag=0&useCheckcode=false&useOrderInfo=false&errorCheckcode=false&action=itemlist%2FSoldQueryAction&prePageNo={2}&buyerNick=&dateBegin=0&dateEnd=0&logisticsService=&orderStatus=&queryOrder=desc&rateStatus=&refund=&sellerNick=&tabCode=latest3Months"; int startIndex = 1; int pageSize = 15; string sdata = GetBillList(cookieStr, data, startIndex, pageSize); SearchOrderInfo rdata = NetDataHandler.ListDataTransformation(sdata); List <T> list = new List <T>(); T tempData = GetData <T>(sdata); list.Add(tempData); double max = Math.Ceiling((double)rdata.TotalNumber / pageSize); for (int i = startIndex + 1; i <= max; i++) { T temp = GetData <T>(GetBillList(cookieStr, data, i, pageSize).ToString()); list.Add(temp); } return(list); }
private T GetData <T>(string data) { Type t = typeof(T); if (t == typeof(string)) { object obj = data; return((T)obj); } if (t == typeof(SearchOrderInfo)) { object obj = NetDataHandler.ListDataTransformation(data); return((T)obj); } throw new Exception(string.Format("暂不支持这种类型{0}", t)); }
public object GetBillDetail(string bid, string cookieStr) { HttpWebRequest request = CreateWebRequest(string.Format("https://trade.taobao.com/trade/detail/trade_order_detail.htm?biz_order_id={0}", bid)); request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, sdch, br"); request.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8"); request.Headers.Add("Cookie", cookieStr); request.Method = "get"; WebResponse response = request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gbk"))) { string rdata = reader.ReadToEnd(); return(NetDataHandler.DetailDataTransformation(rdata)); } }
public string GetBillDetailByUrl(string url, string cookieStr) { try { HttpWebRequest request = CreateWebRequest(url); request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"; request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate, sdch, br"); request.Headers.Add(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.8"); request.Headers.Add("Cookie", cookieStr); request.Method = "get"; WebResponse response = request.GetResponse(); using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("gbk"))) { string rt = reader.ReadToEnd(); return(NetDataHandler.GetDetailDataFromHtml(rt)); } } catch (Exception e) { return(string.Format("获取明细数据出错,请求地址为:{0}, 错误信息:{1}", url, e.Message)); } }