Ejemplo n.º 1
0
        public static LogResult[] Analysis(String path)
        {
            byte[] byteArray = System.Text.Encoding.Default.GetBytes(path);
            char * pArray    = AnalysisLogFile(byteArray);
            int    lines     = getLen();

            Console.WriteLine("C#, loglines:" + lines);
            logInfo[] getLog = new logInfo[1];

            //生成可以在C#中使用的数据
            LogResult[] myLogResult = new LogResult[lines];


            for (int i = 0; i < lines; i++)
            {
                getLog[0]             = (logInfo)Marshal.PtrToStructure((IntPtr)(pArray) + Marshal.SizeOf(typeof(logInfo)) * i, typeof(logInfo));
                myLogResult[i]        = new LogResult();
                myLogResult[i].type   = getLog[0].type;
                myLogResult[i].line   = getLog[0].line;
                myLogResult[i].time_v = getLog[0].time_v;
                myLogResult[i].time   = Convert.ToString(Marshal.PtrToStringAnsi((IntPtr)((byte *)getLog[0].time)));
                myLogResult[i].cmd    = Convert.ToString(Marshal.PtrToStringAnsi((IntPtr)((byte *)getLog[0].cmd)));

                //去掉文件类型引起的回车符问题
                if (myLogResult[i].cmd.Length > 2)
                {
                    myLogResult[i].cmd = myLogResult[i].cmd.Replace("\r", "").Replace("\n", "");
                }

                //Console.WriteLine("C#, line:" + getLog[0].line);

                //添加到扫描结果的数组中
                if (getLog[0].type == 0x06)
                {
                    //扫描结果数组初始话
                    scanResultList = new List <string>();

                    CDLL_scan_results result = (CDLL_scan_results)Marshal.PtrToStructure((IntPtr)(getLog[0].cmd), typeof(CDLL_scan_results));
                    while ((int)(result.Next) != 0 && (IntPtr)(result.result) != null)
                    {
                        String temp = Convert.ToString(Marshal.PtrToStringAnsi((IntPtr)((byte *)result.result)));
                        scanResultList.Add(temp);
                        result = (CDLL_scan_results)Marshal.PtrToStructure((IntPtr)(result.Next), typeof(CDLL_scan_results));
                    }
                    myLogResult[i].scanResultList = scanResultList;
                }
            }
            return(myLogResult);
        }
Ejemplo n.º 2
0
        public void GetMinFreeShipping(Site site)
        {
            logInfo logInfo = new logInfo();
            logInfo.Location = this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;

            //get the minimun purchase amount for free shipping from it's F&Q page
            string url = "https://jet.com/help-center/shipping-and-returns";

            HttpItem httpItem = new HttpItem();
            httpItem.Cookie = string.Empty;
            httpItem.Method = "GET";
            httpItem.Header = null;
            httpItem.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
            httpItem.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36";
            //httpItem.Timeout = 60000 * 5;
            httpItem.URL = url;

            HttpHelper httpHelper = new HttpHelper();

            HttpResult httpResult = null;
            try
            {
                httpResult = httpHelper.GetHtml(httpItem);
                if (httpResult == null)
                {
                    logInfo.KeyInfo = "Remote HTML is null (timeout etc.)";
                    Log4Helper.WarningLog(logInfo);
                }
                else
                {
                    if (httpResult.StatusCode != System.Net.HttpStatusCode.OK)
                    {
                        logInfo.KeyInfo = "Remote HTML is null (timeout etc.)";
                        Log4Helper.WarningLog(logInfo);
                    }
                    else
                    {
                        string content = httpResult.Html;
                        if (content.Length < 200)
                        {
                            return;
                        }

                        HtmlHelper html = new HtmlHelper(content);
                        var fq_node = html.GetNodeByXPath("//div[@class='page_content']/h1");
                        var ans = html.GetNodesByXPath("following-sibling::p", fq_node);

                        Regex minfreeshipping_pattern = new Regex(@"orders\sover\s\$(\d+)");
                        Regex shippingfee_pattern = new Regex(@"fixed\sshipping\sfee\sof\s\$(\d+(\.\d+)?)");
                        int match_min = 0;
                        int match_fee = 0;
                        foreach(HtmlNode a in ans)
                        {
                            if(minfreeshipping_pattern.Match(a.InnerText).Success)
                            {
                                min_shipping = Convert.ToSingle(minfreeshipping_pattern.Match(a.InnerText).Groups[1].Value);
                                match_min = 1;
                            }
                            if (shippingfee_pattern.Match(a.InnerText).Success)
                            {
                                fee_shipping = Convert.ToSingle(shippingfee_pattern.Match(a.InnerText).Groups[1].Value);
                                match_fee = 1;
                            }
                            if(match_min==1&&match_fee==1)
                            {
                                continue;
                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                logInfo.KeyInfo = "Could not get remote HTML";
                Log4Helper.ErrorLog(logInfo);
            }
        }
Ejemplo n.º 3
0
 public SpiderJetCom()
 {
     loginfo = new logInfo();
 }
Ejemplo n.º 4
0
        public override void ListItem(List<Product> products, string keyword, Site site, HttpResult httpResult)
        {
            string content = httpResult.Html; //获取HTML
            this.GetMinFreeShipping(site);

            try
            {
                HtmlHelper html = new HtmlHelper(content);
                HtmlNodeCollection htmlNodeCollection = html.GetNodesByXPath("/div[1]/div[2]/div[@class='product desktop not_mobile']");
                if (htmlNodeCollection == null) { return; }
                foreach (var htmlNode in htmlNodeCollection)
                {
                    //get the url of detail page
                    var a = htmlNode.FirstChild;
                    string href = a.Attributes["href"].Value;
                    href = Regex.Split(href, "/ref=", RegexOptions.IgnoreCase)[0];
                    href = "https://jet.com" + href;

                    //get nodes under a that contain product's information
                    var NodeUnder_a = a.ChildNodes;

                    //product image url
                    var img_node = NodeUnder_a[0];
                    string img_url = img_node.Attributes["style"].Value;
                    Regex im = new Regex("url\\('(.*)'\\)");
                    Match m = im.Match(img_url);
                    if (!m.Success)
                    { continue; }
                    img_url = m.Groups[1].ToString();

                    //product's title
                    var title_node = NodeUnder_a[3];
                    if (title_node == null) { continue; }
                    string title = title_node.InnerText;

                    //prodcut's price
                    var price_node = NodeUnder_a[4];
                    if (price_node == null) { continue; }
                    string price = html.GetNodeByXPath("./div/span[@class='open-sans-regular']", price_node).InnerText;
                    price = price.Replace("$", "").Trim();

                    Product product = new Product();
                    product.Name = title;
                    product.Url = href;
                    product.Img = img_url;
                    product.Price = Convert.ToSingle(price);
                    if (product.Price < 1 || string.IsNullOrWhiteSpace(product.Name) || string.IsNullOrWhiteSpace(product.Img) || string.IsNullOrWhiteSpace(product.Url)
                                || !ValidUrl(product.Url) || !ValidUrl(product.Img))
                    {
                        continue;
                    }

                    if(product.Price > min_shipping)
                    {
                        product.Shipping = 1;
                        product.ShippingFee = 0;
                    }
                    else
                    {
                        product.Shipping = 1;
                        product.ShippingFee = fee_shipping;
                    }

                    product.Created = GetTimeStamp();

                    this.GetDetail(product, site);

                    products.Add(product);
                }

            }
            catch (Exception ex)
            {
                logInfo logInfo = new logInfo();
                logInfo.KeyInfo = site.SiteName + " " + keyword + " ListItem: " + ex.Message;
                logInfo.Location = this.GetType().Name + "." + System.Reflection.MethodBase.GetCurrentMethod().Name;
                Log4Helper.ErrorLog(logInfo);
            }
        }
Ejemplo n.º 5
0
        public static LogResult[] Analysis(String path)
        {
            byte[] byteArray = System.Text.Encoding.Default.GetBytes(path);
            char* pArray = AnalysisLogFile(byteArray);
            int lines = getLen();
            Console.WriteLine("C#, loglines:" + lines);
            logInfo[] getLog = new logInfo[1];

            //生成可以在C#中使用的数据
            LogResult[] myLogResult = new LogResult[lines];

            for (int i = 0; i < lines; i++)
            {
                getLog[0] = (logInfo)Marshal.PtrToStructure((IntPtr)(pArray) + Marshal.SizeOf(typeof(logInfo))*i, typeof(logInfo));
                myLogResult[i] = new LogResult();
                myLogResult[i].type = getLog[0].type;
                myLogResult[i].line = getLog[0].line;
                myLogResult[i].time_v = getLog[0].time_v;
                myLogResult[i].time = Convert.ToString(Marshal.PtrToStringAnsi((IntPtr)((byte*)getLog[0].time)));
                myLogResult[i].cmd = Convert.ToString(Marshal.PtrToStringAnsi((IntPtr)((byte*)getLog[0].cmd)));

                //去掉文件类型引起的回车符问题
                if (myLogResult[i].cmd.Length > 2)
                    myLogResult[i].cmd = myLogResult[i].cmd.Replace("\r", "").Replace("\n", "");

                //Console.WriteLine("C#, line:" + getLog[0].line);

                //添加到扫描结果的数组中
                if (getLog[0].type == 0x06)
                {
                    //扫描结果数组初始话
                    scanResultList = new List<string>();

                    CDLL_scan_results result = (CDLL_scan_results)Marshal.PtrToStructure((IntPtr)(getLog[0].cmd), typeof(CDLL_scan_results));
                    while ((int)(result.Next) != 0 && (IntPtr)(result.result) != null)
                    {
                        String temp = Convert.ToString(Marshal.PtrToStringAnsi((IntPtr)((byte*)result.result)));
                        scanResultList.Add(temp);
                        result = (CDLL_scan_results)Marshal.PtrToStructure((IntPtr)(result.Next), typeof(CDLL_scan_results));
                    }
                    myLogResult[i].scanResultList = scanResultList;
                }
            }
            return myLogResult;
        }