Esempio n. 1
0
        // Define Method
        public Object _openFile(INakoFuncCallInfo info)
        {
            string fileName = info.StackPopAsString();
            string e        = info.StackPopAsString();

            // Exists?
            if (!System.IO.File.Exists(fileName))
            {
                throw new NakoPluginRuntimeException("ファイル『" + fileName + "』は存在しません。");
            }
            // Load
            //string src = File.ReadAllText(fileName);
            string src;

            if (e == "Auto")
            {
                src = StrUnit.LoadFromFileAutoEnc(fileName);
            }
            else
            {
                if (sjis.Contains(e))
                {
                    src = File.ReadAllText(fileName, Encoding.GetEncoding(932));
                }
                else
                {
                    src = File.ReadAllText(fileName, Encoding.GetEncoding(e));
                }
            }
            return(src);
        }
Esempio n. 2
0
 private System.Text.Encoding GetCode()
 {
     using (System.IO.FileStream fr = new FileStream(path, FileMode.Open, FileAccess.Read)){
         byte[] bs   = new byte[Math.Min(fr.Length, 100)];
         int    read = fr.Read(bs, 0, bs.Length);
         if (read == 0)
         {
             return(Encoding.UTF8);
         }
         Encoding e = StrUnit.GetCode(bs);
         return(e);
     }
 }
Esempio n. 3
0
        private string GetNextUrl(string text)
        {
            string str = string.Empty;

            string[] strArray = text.Split(new string[] { "</a>" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < strArray.Length; i++)
            {
                if (strArray[i].IndexOf("下一页") > -1)
                {
                    return(StrUnit.MidStrEx(strArray[i], "href=\"", "\"").Trim());
                }
            }
            return(str);
        }
Esempio n. 4
0
        /// <summary>
        /// ファイルからソースコードを読みこんでパースする
        /// </summary>
        /// <param name="filename"></param>
        public void LoadFromFile(string filename)
        {
            string filename2 = this.RemoveBasePath(filename);
            int    i         = files.IndexOf(filename2);

            if (i >= 0)
            {
                // 二重で取り込みはしない
                return;
            }
            files.Add(filename2);
            string src = StrUnit.LoadFromFileAutoEnc(filename);

            // Parse
            this.ParseEx(src, filename);
        }
Esempio n. 5
0
        public Object _dataGet(INakoFuncCallInfo info)
        {
            string    s = info.StackPopAsString();
            string    e = info.StackPopAsString();
            string    ret;
            WebClient client = new WebClient();

            if (e == "Auto")
            {
                byte[] bytes = client.DownloadData(s);
                ret = StrUnit.ToStringAutoEnc(bytes);
            }
            else
            {
                client.Encoding = Encoding.GetEncoding(e);
                ret             = client.DownloadString(s);
            }
            client.Dispose();
            return(ret);
        }
Esempio n. 6
0
        private string GetData1(string text)
        {
            string str = string.Empty;

            innerHtml = string.Empty;
            string source = string.Empty;

            try
            {
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(text);
                HtmlNode node = null;
                node = document.DocumentNode.SelectSingleNode("//ul[@id='hs-below-list-items']");
                if (node == null)
                {
                    base.updateTextBox("获取商品列表失败", true);
                    throw new Exception("获取商品列表失败");
                }

                foreach (string itemInfo in node.InnerHtml.Split(new string[] { "<li qrdata" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (itemInfo.IndexOf("class=\"list-item") != -1)
                    {
                        //source = StrUnit;
                        DataRow row = base.OutDataTable.NewRow();
                        row["Platform"] = "Ali Express";
                        row["Keyword"]  = base.keywordInf.keyword;
                        row["ItemID"]   = string.Empty;
                        //

                        string goodInfo = StrUnit.MidStrEx(itemInfo, "<a class=\"history-item product", ">");
                        row["Url"]   = StrUnit.MidStrEx(goodInfo, "href=\"//", "\"");
                        row["Title"] = StrUnit.MidStrEx(goodInfo, "title=\"", "\"");
                        row["Price"] = StrUnit.MidStrEx(itemInfo, "itemprop=\"price\">", "</span>");

                        string storeInfo = StrUnit.MidStrEx(itemInfo, "class=\"store-name", "</div>");
                        row["StoreName"] = StrUnit.MidStrEx(storeInfo, "title=\"", "\"");
                        row["StoreUrl"]  = StrUnit.MidStrEx(storeInfo, "href=\"//", "\"");
                        row["SellerID"]  = StrUnit.MidStrEx(storeInfo, "store/", "\"");
                        base.OutDataTable.Rows.Add(row);
                        Thread.Sleep(100);

                        if (string.IsNullOrEmpty(row["Url"].ToString()))
                        {
                            throw new Exception("获取商品列表数据失败! -1");
                        }
                    }
                }

                base.updateTextBox(base.keywordInf.keyword + " 第 " + (page) + " 页获取完成", true);
                if (page >= base.keywordInf.endPage)
                {
                    str = string.Empty;
                    return(str);
                }
                ++page;
                str = "http://www.aliexpress.com/wholesale?SearchText=" + base.keywordInf.keyword + "&page=" + page;
                return(str);
            }
            catch (Exception e)
            {
                base.updateTextBox("GetData Err:" + e.Message, true);
            }

            return(str);
        }
Esempio n. 7
0
        public object _post(INakoFuncCallInfo info)
        {
            string url   = info.StackPopAsString();
            object val   = info.StackPop();//TODO:Array
            string e     = info.StackPopAsString();
            string query = "";

            if (val is string)
            {
                query = (string)val;
            }
            else if (val is NakoVariable)
            {
                List <string> qp  = new List <string>();
                NakoVarArray  arr = (NakoVarArray)val;
                foreach (NakoVariable kv in arr)
                {
                    qp.Add(String.Format("{0}={1}", HttpUtility.UrlEncode(kv.key, Encoding.GetEncoding(e)), HttpUtility.UrlEncode((string)kv.Body, Encoding.GetEncoding(e))));
                }
                query = String.Join("&", qp.ToArray());
            }
            else
            {
                throw new Exception("variable is not NakoVariable or string");
            }

            byte[]         queryBytes = Encoding.ASCII.GetBytes(query);
            HttpWebRequest req        = (HttpWebRequest)WebRequest.Create(url);

            req.Method      = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            using (Stream str = req.GetRequestStream())
            {
                str.Write(queryBytes, 0, queryBytes.Length);
            }
            WebResponse response = req.GetResponse();
            string      ret      = "";

            if (e == "Auto")
            {
                using (Stream sr = response.GetResponseStream()) {
                    byte[] buf  = new byte[32768];
                    int    read = 0;
                    using (MemoryStream ms = new MemoryStream()){
                        do
                        {
                            read = sr.Read(buf, 0, buf.Length);
                            if (read > 0)
                            {
                                ms.Write(buf, 0, read);
                            }
                        } while(read > 0);
                        if (ms.Length > 0)
                        {
                            ret = StrUnit.ToStringAutoEnc(ms.ToArray());
                        }
                    }
                }
            }
            else
            {
                using (StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding(e))) {
                    ret = sr.ReadToEnd();
                }
            }
            return(ret);
        }
Esempio n. 8
0
        public string GetData(string ss)
        {
            string nextUrl = string.Empty;
            string sourse  = "";

            try
            {
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(ss);
                HtmlNode node = document.DocumentNode.SelectSingleNode("//div[@class='nextpage']");
                if (node.SelectSingleNode("//span[@class='current']") != null)
                {
                    byte result = 0;
                    if (!byte.TryParse(node.SelectSingleNode("//span[@class='current']").InnerText.Trim(), out result))
                    {
                        base.updateTextBox(base.keywordInf.keyword + " 获取当前页面出错", true);
                    }
                    if (base.keywordInf.endPage < result)
                    {
                        throw new Exception("已到规定获取的页数,退出");
                    }
                    base.updateTextBox(base.keywordInf.keyword + " 正在获取第 " + result.ToString() + " 页", true);
                }
                if (node.InnerHtml.IndexOf("下一页") > -1)
                {
                    nextUrl = this.GetNextUrl(node.InnerHtml);
                }
                node = document.DocumentNode.SelectSingleNode("//div[@class='s_product']");
                if (node == null)
                {
                    return(nextUrl);
                }
                string[] strArray = node.InnerHtml.Split(new string[] { "<div class=\"s_product_item\">" }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = 0; i < strArray.Length; i++)
                {
                    if (BaseWorkth.DoStop)
                    {
                        return(nextUrl);
                    }
                    if (strArray[i].Contains("<div class=\"s_product_info\">"))
                    {
                        string  str3 = strArray[i].ToString();
                        DataRow row  = base.OutDataTable.NewRow();
                        row["Platform"] = "makepolo.com";
                        row["Url"]      = StrUnit.MidStrEx(str3, "href=\"", "\"");
                        row["ItemId"]   = StrUnit.MidStrEx(row["Url"].ToString(), "product-detail/", ".");
                        row["Keyword"]  = base.keywordInf.keyword;
                        row["Title"]    = StrUnit.MidStrEx(str3, ".html\">", "</a>").Trim();
                        sourse          = StrUnit.MidStrEx(str3, "报价:<strong>", "</strong>");
                        if (sourse.Trim() == "")
                        {
                            sourse = StrUnit.MidStrEx(str3, "报价:", "</");
                        }
                        row["Price"]     = sourse;
                        sourse           = StrUnit.MidStrEx(str3, "class=\"s_product_contact plistk\">", "<span");
                        row["StoreName"] = StrUnit.MidStrEx(sourse, "target=\"_blank\">", "</a>").Trim();
                        row["StoreUrl"]  = StrUnit.MidStrEx(sourse, "<a href=\"", "\"");
                        row["SellerId"]  = StrUnit.MidStrEx(row["StoreUrl"].ToString(), "://", ".");
                        Thread.Sleep(50);
                        base.OutDataTable.Rows.Add(row);
                    }
                }
            }
            catch (Exception exception)
            {
                if (exception.Message != "已到规定获取的页数,退出")
                {
                    base.updateTextBox("GetData取信息异常:" + exception.Message, true);
                }
            }
            return(nextUrl);
        }
Esempio n. 9
0
        private string GetJsonData(string text)
        {
            string str = string.Empty;

            innerHtml = string.Empty;
            string html   = string.Empty;
            string sourse = string.Empty;

            try
            {
                if (text.IndexOf("itemSearchList") == -1)
                {
                    throw new Exception("未知页面内容");
                }
                html = text.Replace(@"\r\n", "").Replace("\\\"", "\"");
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(html);
                HtmlNode node = null;
                node = document.DocumentNode.SelectSingleNode("//div[@id='itemSearchList']");
                if (node == null)
                {
                    throw new Exception("获取商品列表数据失败");
                }
                foreach (string str2 in node.InnerHtml.Split(new string[] { "<div class=\"mod_search_pro\"" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (str2.IndexOf("<div class=\"proImg\"") != -1)
                    {
                        sourse = StrUnit.MidStrEx(str2, "<div class=\"proImg\"", "<p class=\"proPrice\">");
                        DataRow row = base.OutDataTable.NewRow();
                        row["Platform"] = "yhd.com";
                        row["Keyword"]  = base.keywordInf.keyword;
                        row["ItemId"]   = StrUnit.MidStrEx(sourse, "pmid=\"", "\"");
                        if (string.IsNullOrEmpty(row["ItemId"].ToString()))
                        {
                            throw new Exception("获取商品列表数据失败1");
                        }
                        sourse     = StrUnit.MidStrEx(sourse, "href=\"", "\"");
                        sourse     = sourse.StartsWith("//") ? ("http:" + sourse) : sourse;
                        row["Url"] = sourse;
                        if (str2.IndexOf("1号店自营") == -1)
                        {
                            sourse           = StrUnit.MidStrEx(str2, "<p class=\"storeName", "onclick=");
                            row["StoreName"] = StrUnit.MidStrEx(sourse, "title=\"", "\"");
                            row["StoreUrl"]  = StrUnit.MidStrEx(sourse, "href=\"", "\"");
                            row["SellerId"]  = "m-" + StrUnit.MidStrEx(sourse, "merchantid=\"", "\"");
                        }
                        else
                        {
                            row["StoreName"] = "1号店自营";
                            row["StoreUrl"]  = string.Empty;
                            row["SellerId"]  = string.Empty;
                        }
                        sourse       = StrUnit.MidStrEx(str2, "<p class=\"proName clearfix\">", "onclick=");
                        row["Title"] = StrUnit.MidStrEx(sourse, "title=\"", "\"");
                        if (string.IsNullOrEmpty(row["Url"].ToString()))
                        {
                            row["Url"] = StrUnit.MidStrEx(sourse, "href=\"", "\"");
                        }
                        row["Price"] = StrUnit.MidStrEx(str2, "yhdprice=\"", "\"");
                        base.OutDataTable.Rows.Add(row);
                    }
                }
                node = document.DocumentNode.SelectSingleNode("//div[@class='search_select_page']");
                if (node != null)
                {
                    innerHtml = node.InnerHtml;
                    sourse    = StrUnit.MidStrEx(innerHtml, "class=\"next iconSearch\"", "</a>");
                    if (!string.IsNullOrEmpty(sourse))
                    {
                        str = StrUnit.MidStrEx(sourse, "url=\"", "\"") + StrUnit.MidStrEx(sourse, "href=\"", "\"");
                    }
                    sourse = StrUnit.MidStrEx(StrUnit.MidStrEx(innerHtml, "id=\"currentPageNum\"", ">"), "value=\"", "\"");
                    if (string.IsNullOrEmpty(sourse))
                    {
                        sourse = StrUnit.MidStrEx(innerHtml, "pageSearch(", ",");
                    }
                    int result = 0;
                    if (!int.TryParse(sourse, out result))
                    {
                        return(str);
                    }
                    base.updateTextBox(base.keywordInf.keyword + " 第 " + sourse + " 页获取完成", true);
                    if (result >= base.keywordInf.endPage)
                    {
                        str = string.Empty;
                    }
                    //base.updateTextBox(base.keywordInf.keyword + " 已到规定页数,结束", true);
                }
                return(str);
            }
            catch (Exception exception)
            {
                base.updateTextBox("GetJsonData Err:" + exception.Message, true);
            }
            return(str);
        }
Esempio n. 10
0
        public override void Excute()
        {
            try
            {
                DateTime now        = DateTime.Now; //mark of time
                string   url        = string.Empty;
                string   refererUrl = string.Empty; //use refererURLinstead if url in makepolo
                string   text       = string.Empty; //crawled content
                string   s          = string.Empty;
                int      num        = 0;
                base.IniDataTable();                                   //InitDataTable from the base
                base.http = new HttpClientHelper(0x4e20);              //new a HttpClientHelper
                for (int i = 0; i < base.keywordInfList.Count; i++)
                {                                                      //go iterations
                    base.keywordInf = base.keywordInfList[i];          //setup the keyword during this iteration
                    if (string.IsNullOrEmpty(base.keywordInf.keyword)) //skip null or empty keyword
                    {
                        continue;
                    }
                    base.updateTextBox(base.keywordInf.keyword + " 开始查询", true);
                    url = "http://www.yhd.com?forceId=6";
                    byte num3 = 0;
                    while (true)                                                                //open yhd
                    {
                        if (base.http.Get(url).IndexOf("<title>网上超市1号店,省力省钱省时间</title>") != -1) //open success
                        {
                            goto Label_0107;
                        }
                        num3 = (byte)(num3 + 1);  //retry, max: 3 times
                        if (num3 >= 3)
                        {
                            break;
                        }
                        base.updateTextBox("一号店打开主页失败,重试:" + num3.ToString(), true);
                    }
                    num++;
                    continue;
Label_0107:
                    Thread.Sleep(0x7d0);
                    url  = "http://search.yhd.com/c0-0/k" + HttpUtility.UrlEncode(StrUnit.UrlEncode(base.keywordInf.keyword, true).ToUpper()) + "/null/"; //form of url
                    text = base.http.Get(url, "http://www.yhd.com");
                    //Console.WriteLine(text);
                    refererUrl = url;                //copy search url to referer url
                    if (text.Contains("id=\"plist")) // id = "plist
                    {
                        //do nothing?
                    }
                    if (text.Contains("抱歉~没有找到"))
                    {
                        num++; //count the search num
                        base.updateTextBox(base.keywordInf.keyword + " 没有找到相关商品", true);
                        Thread.Sleep(200);
                    }
                    else if (!text.Contains("1号店为您找到"))
                    {
                        num++;
                        base.updateTextBox(base.keywordInf.keyword + " 返回页面错误", true);
                        Log.WritrTemp(text, "未知返回页面");
                    }
                    else
                    {
                        HtmlDocument document = new HtmlDocument();                                      //html document object
                        document.LoadHtml(text);                                                         //load the content got
                        HtmlNode node = null;                                                            //html node init
                        node = document.DocumentNode.SelectSingleNode("//small[@class='result_count']"); //select  'result_count'
                        if (node == null)
                        {
                            num++;
                            base.updateTextBox(base.keywordInf.keyword + " 获取商品数量错误1", false);
                            Log.WriteLog(base.keywordInf.keyword + " 节点不存在://small[@class='result_count']");
                        }
                        else
                        {
                            s = StrUnit.MidStrEx(node.InnerText, "共", "条");
                            int result = 0;
                            if (!int.TryParse(s, out result))
                            {
                                base.updateTextBox(base.keywordInf.keyword + " 获取商品数量错误2", true);
                                num++;
                            }
                            else
                            {
                                for (string str6 = this.GetData(text); !string.IsNullOrEmpty(str6); str6 = this.GetJsonData(text)) //?
                                {
                                    Thread.Sleep(0x7d0);
                                    text = base.http.Get(str6, refererUrl);
                                }
                                TimeSpan span = (TimeSpan)(DateTime.Now - now);
                                base.updateTextBox(string.Concat(new object[] { base.keywordInf.keyword, " 获取完毕,耗时:", span.TotalSeconds, "秒" }), true);
                            }
                        }
                    }
                }
                base.updateTextBox(base.keywordInf.keyword + " 已到规定页数,结束", true);
                base.updateTextBox("共 " + base.keywordInfList.Count.ToString() + " 件商品查询完毕,其中 " + num.ToString() + "件未检索到数据", true);
                base.http.Free();
                base.Stoped = true;
            }
            catch (Exception exception)
            {
                Log.WriteLog("YHDTh Excute Err:" + exception.Message + " ,Err Stack:" + exception.StackTrace);
            }
        }
Esempio n. 11
0
        //excution part
        public override void Excute()
        {
            //TODO: implement the excute function
            try
            {
                DateTime begin = DateTime.Now;
                string url = string.Empty;
                string refererUrl = string.Empty;
                string text = string.Empty;
                string s = string.Empty;
                int num = 0; //count
                base.IniDataTable();
                base.http = new DoNet4.Utilities.HttpClientHelper(0x4e20);

                for (int i = 0; i < base.keywordInfList.Count; i++)
                { //iterate the keyword list
                    base.keywordInf = base.keywordInfList[i];
                    if (string.IsNullOrEmpty(base.keywordInf.keyword))
                    {
                        continue;
                    }
                    base.updateTextBox(base.keywordInf.keyword + " 开始查询", true);
                    url = "http://1688.com";
                    byte retry = 0;
                    while (true)
                    {
                        if (base.http.Get(url).IndexOf("阿里巴巴1688.com - 全球领先的采购批发平台") != -1)
                        {
                            goto Label_search_taobao;
                        }
                        retry = (byte)(retry + 1);
                        if (retry >= 3) { break; }
                        base.updateTextBox("阿里巴巴主页打开失败,重试: " + retry.ToString(), true);
                    }
                    num++;
                    continue;
                    Label_search_taobao:
                    Thread.Sleep(0x7d0);
                    System.Text.Encoding gb2312 = System.Text.Encoding.GetEncoding("gb2312");
                    url = "http://s.1688.com/selloffer/offer_search.htm?keywords=" + HttpUtility.UrlEncode(base.keywordInf.keyword, gb2312).ToUpper();//(base.keywordInf.keyword).ToString();
                    text = base.http.Get(url);
                    refererUrl = url;
                    if (text.Contains("没找到与"))
                    {
                        num++;
                        base.updateTextBox(base.keywordInf.keyword + " 没有找到相关商品", true);
                        Thread.Sleep(200);
                    }
                    else if (text.Contains("淘宝会员(仅限会员名)请在此登录")) {
                        base.updateTextBox(base.keywordInf.keyword + " 阿里巴巴要求登录", true);
                        Thread.Sleep(200);
                    }
                    else
                    {
                        HtmlDocument document = new HtmlDocument();
                        document.LoadHtml(text);
                        HtmlNode node = null;
                        int result = 0;
                        node = document.DocumentNode.SelectSingleNode("//span[@class='sm-widget-offer']");
                        if (node == null)
                        {
                            base.updateTextBox(base.keywordInf.keyword + " node为空(null)!", true);
                        }
                        else
                        {
                            s = StrUnit.MidStrEx(node.InnerHtml, "<em>", "</em>");
                            if (!int.TryParse(s, out result))
                            {
                                base.updateTextBox(base.keywordInf.keyword + " 获取商品数量错误! - 2", true);
                                num++;
                            }
                        }

                        s = StrUnit.MidStrEx(text, "共<em>", "</em>件");
                        
                        if (!int.TryParse(s, out result))
                        {
                            base.updateTextBox(base.keywordInf.keyword + " 获取商品数量错误! - 2", true);
                            num++;
                        }
                        else
                        { //get the useful data, go into iterations
                          //for ()
                            base.updateTextBox("共检索到" + s + " 件相关商品, 开始爬取", true);
                            for (string str6 = this.GetData(text); !string.IsNullOrEmpty(str6); str6 = this.GetData1(text)) //?
                            {
                                Thread.Sleep(0x7d0);
                                text = base.http.Get(str6, refererUrl);
                            }
                            TimeSpan span = (TimeSpan)(DateTime.Now - begin);
                            base.updateTextBox(string.Concat(new object[] { base.keywordInf.keyword, " 获取完毕,耗时:", span.TotalSeconds, "秒" }), true);
                        }

                    }
                }
                base.updateTextBox(base.keywordInf.keyword + " 已到达规定页数,结束", true);
                base.updateTextBox("共 " + base.keywordInfList.Count.ToString() + " 件商品查询完毕,其中 " + num.ToString() + "件未检索到数据", true);
                base.http.Free();
                base.Stoped = true;
            }
            catch (Exception e)
            {
                //exception handling
                Log.WriteLog("taobaoTh Excute Err:" + e.Message + " ,Err Stack:" + e.StackTrace);
            }
        }
Esempio n. 12
0
        private string GetData1(string text)
        {
            string str = string.Empty;
            innerHtml = string.Empty; //innerHtml content
            string source = string.Empty;
            try
            {
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(text);
                HtmlNode node = null;
                node = document.DocumentNode.SelectSingleNode("//ul[@id='sm-offer-list']");
                if (node == null)
                {
                    base.updateTextBox("获取商品列表失败", true);
                    throw new Exception("获取商品列表失败");
                }

                foreach (string str2 in node.InnerHtml.Split(new string[] { "<li t" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (str2.IndexOf("-rank") != -1)
                    {
                        source = StrUnit.MidStrEx(str2, "rank", "</li>");
                        DataRow row = base.OutDataTable.NewRow();
                        row["Platform"] = "1688.com";
                        row["Keyword"] = base.keywordInf.keyword;
                        row["ItemID"] = StrUnit.MidStrEx(source, "t-offer-id=\"", "\"");
                        row["SellerId"] = StrUnit.MidStrEx(source, "t-member-id=\"", "\"");
                        string goodInfo = string.Empty;
                        goodInfo = StrUnit.MidStrEx(source, "sm-offer-photo sw-dpl-offer-photo", "</div>");
                        row["Url"] = StrUnit.MidStrEx(goodInfo, "href=\"", "\"");
                        row["Title"] = StrUnit.MidStrEx(goodInfo, "title=\"", "\"");
                        string priceInfo = string.Empty;
                        priceInfo = StrUnit.MidStrEx(source, "<div class=\"s-widget-offershopwindowprice sm-offer-price sw-dpl-offer-price\">", "</div>");
                        row["Price"] = StrUnit.MidStrEx(priceInfo, "title=\"&yen;", "\"");
                        string companyInfo = string.Empty;
                        companyInfo = StrUnit.MidStrEx(source, "<div class=\"s-widget-offershopwindowcompanyinfo sm-offer-company sw-dpl-offer-company\">", "</div>");
                        row["StoreName"] = StrUnit.MidStrEx(companyInfo, "title=\"", "\"");
                        row["StoreUrl"] = StrUnit.MidStrEx(companyInfo, "href=\"", "\"");
                        base.OutDataTable.Rows.Add(row);
                        Thread.Sleep(50);


                        if (string.IsNullOrEmpty(row["ItemID"].ToString()))
                        {
                            throw new Exception("获取商品列表数据失败! - 1");
                        }
                    }

                }//end of info retrieving
                 /*
                 HtmlNode node2;
                 //node2 = new HtmlNode();
                 node2 = document.DocumentNode.SelectSingleNode("//div[@id='fui_widget_4']/span");
                 string pageSelectionInfo = StrUnit.MidStrEx(text, "<span class=\"fui-paging-list\">", "</span>");
                 string nextPage = string.Empty;
                 if (node2 != null)
                 {
                     //innerHtml = node.InnerHtml;
                     foreach (string pageInfo in node2.InnerHtml.Split(new string[] { "<a href=#" }, StringSplitOptions.RemoveEmptyEntries))
                     {
                         if (pageInfo.IndexOf("fui-next") != -1)
                         {
                             nextPage = StrUnit.MidStrEx(pageInfo, "data-page=\"", "\"");
                             break;
                         }

                         int resultPage = 0;
                         if (!int.TryParse(nextPage, out resultPage))
                         {
                             System.Text.Encoding gb2312 = System.Text.Encoding.GetEncoding("gb2312");
                             str = "https://s.1688.com/selloffer/offer_search.htm?keywords=" + HttpUtility.UrlEncode(base.keywordInf.keyword, gb2312).ToUpper() + "&beginPage=" + nextPage;
                             return str;
                         }
                         base.updateTextBox(base.keywordInf.keyword + " 第 " + (resultPage-1) + " 页获取完成", true);
                         if (resultPage > base.keywordInf.endPage)
                         {
                             str = string.Empty;
                         }

                     }//end of for each
                     //source = StrUnit.
                     return str;
                 }*/
                base.updateTextBox(base.keywordInf.keyword + " 第 " + (page) + " 页获取完成", true);
                if (page >= base.keywordInf.endPage)
                {
                    str = string.Empty;
                    return str;
                }
                ++page;
                System.Text.Encoding gb2312 = System.Text.Encoding.GetEncoding("gb2312");
                str = "https://s.1688.com/selloffer/offer_search.htm?keywords=" + HttpUtility.UrlEncode(base.keywordInf.keyword, gb2312).ToUpper() + "&beginPage=" + page;
                return str;


            }
            catch (Exception e)
            {
                base.updateTextBox("GetData Err:" + e.Message, true);
            }
            return str;
        }
Esempio n. 13
0
        //Get data
        private string GetData(string text)
        {
            string str = string.Empty;

            innerHtml = string.Empty;
            string source = string.Empty;

            try
            {
                text = StrUnit.MidStrEx(text, "\"normalList\":[", "</html>");
                foreach (string itemInfo in text.Split(new string[] { "{\"productId\":" }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (itemInfo.IndexOf("productId_f") != -1)
                    {
                        string  info = "\"productID\":" + itemInfo;
                        DataRow row  = base.OutDataTable.NewRow();
                        row["Platform"]  = "alibaba.com";
                        row["Keyword"]   = base.keywordInf.keyword;
                        row["ItemID"]    = StrUnit.MidStrEx(info, "\"productID\":\"", "\",");
                        row["SellerID"]  = StrUnit.MidStrEx(info, "supplierId\":\"", "\"");
                        row["Url"]       = StrUnit.MidStrEx(info, "productHref\":\"//", "\"");
                        row["Title"]     = StrUnit.MidStrEx(info, "productPuretitle\":\"", "\"");
                        row["Price"]     = StrUnit.MidStrEx(info, "\"price\":\"US $", "\"");
                        row["StoreName"] = StrUnit.MidStrEx(info, "\"supplierName\":\"", "\"");
                        row["StoreUrl"]  = StrUnit.MidStrEx(info, "supplierHref\":\"", "\"");
                        base.OutDataTable.Rows.Add(row);
                        Thread.Sleep(100);
                        if (string.IsNullOrEmpty(row["ItemID"].ToString()))
                        {
                            throw new Exception("获取商品列表数据失败! - 1");
                        }
                    }
                    else
                    {
                        throw new Exception("Json data 获取错误");
                    }
                }//end of foreach

                base.updateTextBox(base.keywordInf.keyword + " 第 " + (page) + " 页获取完成", true);
                if (page >= base.keywordInf.endPage)
                {
                    str = string.Empty;
                    return(str);
                }
                ++page;
                str = "http://www.alibaba.com/products/F0/" + base.keywordInf.keyword + "/" + page + ".html";
                return(str);

                /*
                 * HtmlDocument document = new HtmlDocument();
                 * document.LoadHtml(text);
                 * HtmlNode node = null;
                 * node = document.DocumentNode.SelectSingleNode("//div[@data-content='abox-ProductNormalList']");
                 *
                 * if(node == null)
                 * {
                 *  base.updateTextBox("获取商品列表失败!",true);
                 *  throw new Exception("获取商品列表失败");
                 * }
                 *
                 * foreach (string itemInfo in node.InnerHtml.Split(new string[] { "<div class=\"m-product-item"},StringSplitOptions.None))
                 * {
                 *  if (itemInfo.IndexOf("data-role=\"")!=-1)
                 *  {
                 *
                 *  }
                 * }//end of foreach
                 *
                 * base.updateTextBox(base.keywordInf.keyword + " 第 " + (page) + " 页获取完成", true);
                 * if (page >= base.keywordInf.endPage)
                 * {
                 *  str = string.Empty;
                 *  return str;
                 * }
                 ++page;
                 * str = "http://www.alibaba.com/products/F0/"+base.keywordInf.keyword+"/"+page+".html";
                 * return str;
                 */
            }
            catch (Exception e)
            {
                base.updateTextBox("GetData Err:" + e.Message, true);
            }

            return(str);
        }