示例#1
0
        private void navigate(string url = null)
        {
            if (_browser == null)
            {
                _browser = new IE();
            }

            if (url == null)
            {
                _browser.GoTo("http://weather.nsu.ru/");
            }
            else
            {
                _browser.GoToNoWait(url);
            }
        }
示例#2
0
        public static void ReportProcessRenew()
        {
            CloseInternetExplorers();

            var totaltodayReportList = MySqlHelper.PopulateTodayRenewAdsForReport();

            ServiceLog.CraigslistErrorLog("*****************************************NUMBEROFADTORUN = " + totaltodayReportList.Count + "*******************************************");

            int showedAds = 0;

            int flagedAds = 0;

            foreach (var vehicle in totaltodayReportList)
            {
                try
                {
                    if (_browser == null)
                    {
                        _browser =
                            new IE(vehicle.CraigslistUrl);
                    }
                    else
                    {
                        _browser.GoToNoWait(vehicle.CraigslistUrl);
                    }
                    _browser.ShowWindow(NativeMethods.WindowShowStyle.Hide);

                    System.Threading.Thread.Sleep(1000);


                    if (_browser.Html.Contains("This posting has been flagged for removal"))
                    {
                        MySqlHelper.NonShowAds(vehicle.AdTrackingId);

                        ServiceLog.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == FLAGGED");
                        flagedAds++;
                    }
                    else
                    {
                        MySqlHelper.ShowAds(vehicle.AdTrackingId);
                        ServiceLog.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == SHOWED");
                        showedAds++;
                    }



                    System.Threading.Thread.Sleep(200);
                }
                catch (Exception ex)
                {
                    ServiceLog.CraigslistErrorLog(ex.Message);
                }
            }

            if (_browser != null)
            {
                _browser.ClearCache();

                _browser.ClearCookies();

                _browser.Close();

                _browser = null;
            }

            var percentage =
                Math.Ceiling(((double)showedAds /
                              totaltodayReportList.Count()) * 100);

            var builder = new StringBuilder();

            builder.Append("NUMBER OF RENEW ADS TODAY = <b>" + totaltodayReportList.Count + ".....");

            builder.Append("NUMBER OF RENEW ADS SHOWED = " + showedAds + ".....");

            builder.Append("NUMBER OF RENEW ADS FLAGGED = " + flagedAds + "....");

            builder.Append("PERCENTAGE = <b>" + percentage.ToString(CultureInfo.InvariantCulture) + "%" + ".......");

            SmsHelper.SendMessageToAtt("Craigslist Report", builder.ToString());

            ServiceLog.CraigslistErrorLog("*****************************************SHOWED = " + showedAds + "*******************************************");

            ServiceLog.CraigslistErrorLog("*****************************************FLAGGED = " + flagedAds + "*******************************************");

            ServiceLog.CraigslistErrorLog("*****************************************DONE*******************************************");
        }
示例#3
0
        public static void RenewAdsProcess(int splitPart)
        {
            var totalrenewList = MySqlHelper.PopulateAvailableRenewAds();

            var renewList = totalrenewList.Skip(totalrenewList.Count * splitPart / 2).Take(totalrenewList.Count / 2).ToList();

            var ieProcesses = Process.GetProcessesByName("iexplore");

            if (ieProcesses.Any() && ieProcesses.Count() > 5)
            {
                foreach (Process ie in ieProcesses)
                {
                    ie.Kill();
                }
            }

            if (_browser != null)
            {
                _browser.ClearCache();

                _browser.ClearCookies();

                _browser.Close();

                _browser = null;
            }


            if (_browser != null && IsAlreadyLogin())
            {
                System.Threading.Thread.Sleep(2000);

                _browser.Span(Find.ById("ef")).Links.First().Click();

                System.Threading.Thread.Sleep(3000);
            }



            foreach (var vehicle in renewList)
            {
                try
                {
                    if (_browser == null)
                    {
                        _browser = new IE(vehicle.CraigslistCityUrl + "search/ctd?zoomToPosting=&query=" + vehicle.CLPostingId + "&srchType=A&minAsk=&maxAsk=");
                    }
                    else
                    {
                        _browser.GoToNoWait(vehicle.CraigslistCityUrl + "search/ctd?zoomToPosting=&query=" + vehicle.CLPostingId + "&srchType=A&minAsk=&maxAsk=");
                    }

                    _browser.ShowWindow(NativeMethods.WindowShowStyle.ShowMaximized);

                    System.Threading.Thread.Sleep(2000);

                    if (_browser.Html.Contains("Found: "))
                    {
                        if (vehicle.AutoID == 1 || (renewList.Any(x => x.AutoID == vehicle.AutoID - 1) && !renewList.First(x => x.AutoID == vehicle.AutoID - 1).CraigslistAccountName.Equals(vehicle.CraigslistAccountName)))
                        {
                            if (_browser == null)
                            {
                                _browser = new IE("https://accounts.craigslist.org/");
                            }
                            else
                            {
                                _browser.GoTo("https://accounts.craigslist.org/");
                            }

                            if (_browser != null && IsAlreadyLogin())
                            {
                                System.Threading.Thread.Sleep(2000);

                                _browser.Span(Find.ById("ef")).Links.First().Click();

                                System.Threading.Thread.Sleep(3000);

                                _browser.ClearCache();

                                _browser.ClearCookies();

                                _browser.Close();

                                _browser = null;
                            }


                            if (_browser == null)
                            {
                                _browser = new IE("https://accounts.craigslist.org/");
                            }
                            else
                            {
                                _browser.GoTo("https://accounts.craigslist.org/");
                            }


                            _browser.TextField(Find.ByName("inputEmailHandle")).TypeText(vehicle.CraigslistAccountName);

                            _browser.TextField(Find.ByName("inputPassword")).TypeText(vehicle.CraigslistAccountPassword);

                            System.Threading.Thread.Sleep(2000);

                            _browser.Buttons.First().Click();
                        }
                        else
                        {
                            if (_browser != null)
                            {
                                _browser.GoTo("https://accounts.craigslist.org/");
                            }
                            else
                            {
                                _browser = new IE("https://accounts.craigslist.org/");
                            }

                            if (!IsAlreadyLogin())
                            {
                                _browser.ClearCache();

                                _browser.ClearCookies();

                                _browser.Close();

                                _browser = null;

                                _browser = new IE("https://accounts.craigslist.org/");

                                _browser.TextField(Find.ByName("inputEmailHandle")).TypeText(vehicle.CraigslistAccountName);

                                _browser.TextField(Find.ByName("inputPassword")).TypeText(vehicle.CraigslistAccountPassword);

                                System.Threading.Thread.Sleep(2000);

                                _browser.Buttons.First().Click();
                            }
                        }

                        System.Threading.Thread.Sleep(2000);

                        _browser.GoTo("https://post.craigslist.org/manage/" + vehicle.CLPostingId);


                        if (_browser.Buttons.Any(x => x.Value == "Renew this Posting"))
                        {
                            System.Threading.Thread.Sleep(1000);

                            _browser.Button(Find.ByValue("Renew this Posting")).ClickNoWait();

                            System.Threading.Thread.Sleep(4000);

                            MySqlHelper.ShowAdsButEligibleForRenew(vehicle.AdTrackingId);

                            //ServiceLog.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == RENEWED");
                        }
                        else
                        {
                            MySqlHelper.ShowAdsButIneligibleForRenew(vehicle.AdTrackingId);

                            _browser.GoTo("https://accounts.craigslist.org/");

                            System.Threading.Thread.Sleep(2000);

                            _browser.Span(Find.ById("ef")).Links.First().Click();

                            System.Threading.Thread.Sleep(3000);

                            _browser.ClearCache();

                            _browser.ClearCookies();

                            _browser.Close();

                            _browser = null;

                            //.CraigslistErrorLog(vehicle.AdTrackingId.ToString(CultureInfo.InvariantCulture) + " == NOT ELIGIBLE TO RENEW");
                        }
                    }
                    else
                    {
                        MySqlHelper.DeleteTracking(vehicle.AdTrackingId);
                    }

                    System.Threading.Thread.Sleep(10000);
                }
                catch (Exception ex)
                {
                    //throw new Exception(ex.Message);
                }
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            IE     ie  = null;
            String url = "http://localhost:8000/windows/pages/multipleframe.html";

            url = "baidu.com";
//            url = "sina.com";
            String file = "d:\\test2.png";

            Boolean debug = false;

            if (args.Length >= 2)
            {
                url  = args[0];
                file = args[1];
            }

            if (args.Length >= 3 && args[2] == "debug")
            {
                debug = true;
            }
            Console.WriteLine("Capture " + url + " to " + file);

            ie = new IE();

            ie.GoToNoWait(url);
            try
            {
                ie.ShowWindow(WatiN.Core.Native.Windows.NativeMethods.WindowShowStyle.Maximize);


                Stream       s      = new FileStream("beidou_ad.user.js", FileMode.Open);
                StreamReader sr     = new StreamReader(s, Encoding.Default);
                String       script = sr.ReadToEnd().ToString();

                ie.WaitForComplete(30);

                Thread.Sleep(1000);

                ie.RunScript(script);

                if (debug)
                {
                    Stream       st = new FileStream("html.txt", FileMode.Create);
                    StreamWriter sw = new StreamWriter(st, Encoding.Default);
                    sw.Write(ie.Html);
                    sw.Close();
                    st.Close();
                }

                //插入截图判断逻辑

                ie.CaptureWebPageToFile(file);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            finally
            {
                if (ie != null)
                {
                    int procId = ie.ProcessID;

                    foreach (Process thisproc in System.Diagnostics.Process.GetProcesses())
                    {
                        if (thisproc.Id == procId)
                        {
                            Execute("ntsd -c q -p " + procId, 1000);
                            break;
                        }
                    }
                }
            }
        }