Beispiel #1
0
 public override decimal GetPrice()
 {
     try
     {
         string priceUrl = GetWebSiteInfo().BaseUrl + "/emall/SNProductStatusView?storeId={0}&catalogId={1}&productId={2}&cityId=9265&_={3}";
         var reg = Regex.Match(ProLink, GetWebSiteInfo().BaseUrl + "/emall/prd_(\\d+)_(\\d+)_-\\d_(\\d+)_.html");
         if (!reg.Success)
             return 0;
         var url = String.Format(priceUrl, reg.Groups[1].Value, reg.Groups[2].Value, reg.Groups[3].Value,
                                 Utils.GetJsonTime());
         using (var http = new HttpHelper(url, "", SiteEncoding, "", ProLink, ""))
         {
             var html = http.GetHtml();
             var str = RegexHelper.Match(html, "\"promotionPrice\":\\s*\"([^\"]+)\"");
             var mStr = RegexHelper.Match(html, "\"itemPrice\":\\s*\"([^\"]+)\"");
             _mkPrice = (mStr.IsNullOrEmpty() ? 0M : Convert.ToDecimal(mStr.Replace(",", "")));
             var salesOrg = RegexHelper.Match(html, "\"salesOrg\":\\s*\"([^\"]+)\"");
             var deptNo = RegexHelper.Match(html, "\"deptNo\":\\s*\"([^\"]+)\"");
             var vendor = RegexHelper.Match(html, "\"vendor\":\\s*\"([^\"]+)\"");
             _stockUrl = GetWebSiteInfo().BaseUrl +
                         "/emall/SNProductSaleView?storeId={0}&catalogId={1}&productId={2}&salesOrg={3}&&deptNo={4}&vendor={5}&cityId=9265&_={6}";
             _stockUrl = String.Format(_stockUrl, reg.Groups[1].Value, reg.Groups[2].Value, reg.Groups[3].Value,
                                       salesOrg, deptNo, vendor, Utils.GetJsonTime());
             return Convert.ToDecimal(str.Replace(",", ""));
         }
     }
     catch (Exception ex)
     {
         FileHelper.WriteException(ex);
         return 0;
     }
 }
Beispiel #2
0
 public override IEnumerable<string> GetUrlList(string listUrl)
 {
     try
     {
         using (var http = new HttpHelper(listUrl, SiteEncoding))
         {
             var html = http.GetHtml();
             var url = http.GetRequestUrl();
             if (Regex.IsMatch(url, "^http://www.newegg.com.cn/Product/[0-9a-zA-Z\\-]+.htm$"))
                 return new List<string> {url};
             if (!html.IsNullOrEmpty())
                 html = RegexHelper.ClearTrn(html);
             var showList = HtmlCls.GetHtmlById(html, "itemGrid1");
             var list =
                 RegexHelper.Matches(showList, "(http://www.newegg.com.cn/Product/[0-9a-zA-Z\\-]+.htm)").Distinct()
                     .ToList();
             return
                 list.Where(t => !t.IsNullOrEmpty()).Select(
                     t => Utils.GetAbsoluteUrl(GetWebSiteInfo().BaseUrl, t)).ToList();
         }
     }
     catch (Exception)
     {
         return new List<string>();
     }
 }
Beispiel #3
0
 public override int GetStockCode()
 {
     try
     {
         string stockUrl = GetWebSiteInfo().BaseUrl +
                           "/interfaces/stock/hasStock.action?itemid={0}&province=71000000&city=71030000&county=71031500&a={1}";
         //成都青羊区
         //var data= {"productId":0,"storeStatus":"0","useTrans":"宅急送","goodsPattern":"SMI","isArrive":"1","isArrivePay":"1","freightPrice":"0","comeTime":"9月29日","refuseOrderTime":"7小时51分钟"}
         //var states = ["现货","预订","无货","在途"];
         var proId = RegexHelper.Match(ProLink, "product/([\\d]+).html");
         var url = String.Format(stockUrl, proId, RandomHelper.Random().NextDouble());
         using (var http = new HttpHelper(url, SiteEncoding))
         {
             var html = http.GetHtml();
             if (!html.IsNullOrEmpty())
                 html = RegexHelper.ClearTrn(html);
             var status = RegexHelper.Match(html, "\"storeStatus\":\"([\\d]+)\"");
             return (status == "0" ? 1 : 0);
         }
     }
     catch (Exception ex)
     {
         FileHelper.WriteException(ex);
         return -1;
     }
 }
Beispiel #4
0
 public void HttpHelperTest()
 {
     using (var http = new HttpHelper("www.baidu.com", Encoding.UTF8))
     {
         var html = http.GetHtml();
         Console.Write(html);
     }
 }
Beispiel #5
0
 public static string GetHtmlByUrl(string url, Encoding encoding = null, string cookie = "")
 {
     encoding = (encoding ?? Encoding.Default);
     using (var http = new HttpHelper(url, "", encoding, cookie, "", ""))
     {
         return http.GetHtml();
     }
 }
Beispiel #6
0
 public void PostFilesTest()
 {
     using (var http = new HttpHelper("http://file.dayeasy.dev/uploader?type=2", "post", Encoding.UTF8, ""))
     {
         http.AddFiles(new List<string> { "d:\\big.mp4" });
         var html = http.GetHtml();
         Console.Write(html);
     }
 }
Beispiel #7
0
 protected static void GetHtml(Encoding encoding)
 {
     if (DocHtml.IsNullOrEmpty())
     {
         using (var http = new HttpHelper(ProLink, encoding))
         {
             DocHtml = http.GetHtml();
             if (!DocHtml.IsNullOrEmpty())
                 DocHtml = RegexHelper.ClearTrn(DocHtml);
         }
     }
 }
Beispiel #8
0
 public override int GetStockCode()
 {
     try
     {
         if (_stockUrl.IsNullOrEmpty())
             GetPrice();
         using (var http = new HttpHelper(_stockUrl, "", SiteEncoding, "", ProLink, ""))
         {
             var html = http.GetHtml();
             var status = RegexHelper.Match(html, "\"productStatus\":\\s*\"([^\"]+)\"");
             var offset = RegexHelper.Match(html, "\"shipOffset\":\\s*\"([^\"]+)\"");
             return ConvertHelper.StrToInt(status, 0)*10 + ConvertHelper.StrToInt(offset, 0);
         }
     }
     catch (Exception ex)
     {
         FileHelper.WriteException(ex);
         return -1;
     }
 }
Beispiel #9
0
 public override int GetStockCode()
 {
     try
     {
         GetHtml(SiteEncoding);
         var proNum = HtmlCls.GetHtmlByCss(DocHtml, "prodNum").ToList()[1];
         proNum = Regex.Replace(proNum, "</?[0-9a-zA-Z]+[^>]*>", "").Replace("商品编号:", "").Trim();
         var stockUrl = GetWebSiteInfo().BaseUrl + "/ec/homeus/browse/exactMethod.jsp?goodsNo={0}&city=71010000";
         stockUrl = String.Format(stockUrl, proNum);
         using (var http = new HttpHelper(stockUrl, SiteEncoding))
         {
             var html = http.GetHtml();
             var str = RegexHelper.Match(html, "\"result\":\"([a-zA-Z])\"");
             return (str == "Y" ? 1 : 0);
         }
     }
     catch (Exception)
     {
         return -1;
     }
 }
Beispiel #10
0
 private DResult<string> GetPrepayId(string tradeNo, decimal price, string subject)
 {
     var encoding = Encoding.GetEncoding(Config.Charset);
     var dict = Config.BaseParams();
     dict.Add("out_trade_no ", tradeNo);
     dict.Add("total_fee", price.ToString("f2"));
     dict.Add("body", subject);
     dict.Add("sign", dict.Md5Sign(Config.PrivateKey));
     Logger.Info(JsonHelper.ToJson(dict, indented: true));
     using (var http = new HttpHelper(Config.Gateway, "POST", encoding, dict.ParamsXml()))
     {
         http.SetContentType("text/xml");
         var html = http.GetHtml();
         Logger.Info(html);
         html = html.As<IRegex>().Replace("\n", string.Empty);
         var dto = XmlHelper.XmlDeserialize<ReturnWeixinDto>(html, encoding);
         if (dto == null || dto.return_code != "SUCCESS")
             return DResult.Error<string>(dto?.return_msg ?? "支付接口异常");
         return DResult.Succ(dto.prepay_id);
     }
 }
Beispiel #11
0
 public override IEnumerable<string> GetUrlList(string listUrl)
 {
     try
     {
         using (var http = new HttpHelper(listUrl, SiteEncoding))
         {
             var html = http.GetHtml();
             html = (!html.IsNullOrEmpty() ? RegexHelper.ClearTrn(html) : http.GetHtml());
             if (html.IsNullOrEmpty())
                 return new List<string>();
             var showList = HtmlCls.GetHtmlByCss(html, "pic");
             var list =
                 showList.Select(t => RegexHelper.Match(t, "<a[^>]*href=[\"']?([^\"'>;]+)(;[^\"'>]*)?[\"']?[^>]*>"))
                     .Distinct().ToList();
             return list.Where(t => !t.IsNullOrEmpty()).Select(t => Utils.GetAbsoluteUrl(GetWebSiteInfo().BaseUrl, t)).ToList();
         }
     }
     catch (Exception)
     {
         return new List<string>();
     }
 }
Beispiel #12
0
 public override IEnumerable<string> SearchWord(string word)
 {
     try
     {
         string searchUrl = GetWebSiteInfo().BaseUrl +
                            "/s/ref=nb_sb_noss_1?__mk_zh_CN=%E4%BA%9A%E9%A9%AC%E9%80%8A%E7%BD%91%E7%AB%99&url=search-alias%3Daps&field-keywords={0}";
         var url = String.Format(searchUrl, Utils.UrlEncode(word, SiteEncoding));
         using (var http = new HttpHelper(url, SiteEncoding))
         {
             var html = http.GetHtml();
             if (!html.IsNullOrEmpty())
                 html = RegexHelper.ClearTrn(html);
             var showList = HtmlCls.GetHtmlById(html, "atfResults") + HtmlCls.GetHtmlById(html, "btfResults");
             var list =
                 HtmlCls.GetHtmlByCss(showList, "productImage").Select(
                     t => RegexHelper.Match(t, "<a[^>]*href=[\"']?([^\"'>]+)(#[^\"'>]*)?[\"']?[^>]*>")).Distinct().
                     ToList();
             return list;
         }
     }
     catch(Exception ex)
     {
         FileHelper.WriteException(ex);
         return new List<string>();
     }
 }
Beispiel #13
0
 public override IEnumerable<string> GetUrlList(string listUrl)
 {
     try
     {
         using (var http = new HttpHelper(listUrl, SiteEncoding))
         {
             var html = http.GetHtml();
             html = RegexHelper.ClearTrn(html);
             var showList = HtmlCls.GetHtmlById(html, "proShow");
             var linkReg = "<a[^>]*href=[\"']?(" + GetWebSiteInfo().BaseUrl +
                           "/emall/prd_\\d+_\\d+_-\\d+_\\d+_.html)[\"']?[^>]*>";
             var list = RegexHelper.Matches(showList, linkReg).Distinct().ToList();
             return list;
         }
     }
     catch(Exception ex)
     {
         FileHelper.WriteException(ex);
         return new List<string>();
     }
 }
Beispiel #14
0
 public override int GetStockCode()
 {
     try
     {
         var stockUrl = GetWebSiteInfo().BaseUrl +
                        "/Ajax/Product/AjaxProductInventory.aspx?stockId=54&productID={0}&isFirstLoad=false";
         var url = String.Format(stockUrl, GetProductId());
         using (var http = new HttpHelper(url, SiteEncoding))
         {
             var str = http.GetHtml();
             if (str.IndexOf("成都仓有货") >= 0)
                 return 1;
             return 0;
         }
     }
     catch
     {
         return -1;
     }
 }
Beispiel #15
0
        /// <summary>
        /// 根据url地址下载文件(主要是图片文件)
        /// </summary>
        /// <param name="url">文件地址</param>
        /// <param name="filename">保存的文件名(含路径)</param>
        /// <returns></returns>
        public static bool UrlDownLoadToFile(string url, string filename)
        {
            bool result;

            using (var http = new HttpHelper(url))
            {
                result = http.SaveFile(filename);
                Thread.Sleep(100);
            }
            return result;
        }
Beispiel #16
0
        /// <summary>
        /// 获取产品价格
        /// </summary>
        /// <param name="jdNum">jd产品编号</param>
        /// <returns></returns>
        public static decimal GetPriceFromCart(string jdNum)
        {
            const string addcart = "http://cart.360buy.com/cart/addSkuToCartAsync.action?pid={0}&ptype=1&pcount={1}&rd={2}";
            const string cart = "http://cart.360buy.com/cart/getCurrentCartNew.action?rd={0}";
            decimal price = 0;
            int count = 0;
            while ((price == 0 || price == 99M) && count < 2)
            {
                count++;
                try
                {
                    using (
                        var http = new HttpHelper(String.Format(addcart, jdNum, 1, Utils.GetJsonTime()), Encoding.UTF8))
                    {
                        http.GetCookie();
                        http.SetUrl(String.Format(cart, Utils.GetJsonTime()));
                        var html = http.GetHtml();
                        string sprice = RegexHelper.Match(html, "\"finalPrice\":\"([^\"]+)\"");
                        price = Convert.ToDecimal(sprice.Replace(",", ""));
                    }
                }
                catch
                {
                    price = 0;
                }
            }

            #region 旧方式

            //string url = String.Format(cart, (new Random().NextDouble()));
            //int count = 0;
            //while ((price == 0 || price == 99M) && count < 2)
            //{
            //    count++;
            //    try
            //    {
            //        string doc = HtmlCls.GetHtmlByUrl(url,
            //                                          "cart-main=\"{&spg&:{&ps&:[{&i&:" + jdNum +
            //                                          "$&n&:1$&at&:0$&ct&:1}]}$&y&:{}$&by&:false$&rs&:[" + jdNum +
            //                                          "]$&tm&:&" + Utils.GetTimeNow() +"&$&st&:&g&}\"", Encoding.UTF8, _useProxy);
            //        string sprice = RegexHelper.Match(doc, "\"finalPrice\":\"([^\"]+)\"");
            //        price = Convert.ToDecimal(sprice.Replace(",", ""));
            //    }
            //    catch (Exception)
            //    {
            //        price = 0;
            //    }
            //}

            #endregion

            return price;
        }