Ejemplo n.º 1
0
        /// <summary>
        /// 初始化与手机App的连接
        /// </summary>
        private AndroidAppAccess InitAppAccess()
        {
            AndroidAppAccess            appAccess  = new AndroidAppAccess();
            Dictionary <string, string> initParams = new Dictionary <string, string>();

            initParams.Add("deviceName", "HUAWEI G700-U00");
            initParams.Add("platformVersion", "4.2");
            initParams.Add("appPackage", "com.linkedin.android");
            initParams.Add("appActivity", "com.linkedin.android.authenticator.LaunchActivity");;
            initParams.Add("url", "http://127.0.0.1:4723/wd/hub");
            appAccess.InitDriver(initParams);

            //留出五秒钟的实际,等待手机被唤醒,及app被启动
            Thread.Sleep(5000);

            return(appAccess);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 初始化与手机App的连接
        /// </summary>
        private AndroidAppAccess InitAppAccess()
        {
            AndroidAppAccess            appAccess  = new AndroidAppAccess();
            Dictionary <string, string> initParams = new Dictionary <string, string>();

            initParams.Add("deviceName", "192.168.124.101:5555");
            initParams.Add("platformVersion", "6.0");
            initParams.Add("appPackage", "com.taobao.taobao");
            initParams.Add("appActivity", "com.taobao.tao.welcome.Welcome");
            initParams.Add("url", "http://127.0.0.1:4723/wd/hub");
            appAccess.InitDriver(initParams);

            //留出五秒钟的实际,等待手机被唤醒,及app被启动
            Thread.Sleep(5000);

            return(appAccess);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 判断是否需要登出
        /// </summary>
        /// <param name="appAccess"></param>
        private bool CheckNeedLogout(AndroidAppAccess appAccess)
        {
            AndroidElement navElement = this.GetNavElement(appAccess, false);
            //判断存在“立即加入”和“登录”按钮
            bool hasLogout = appAccess.CheckCurrentPageContainText(new string[] { "立即加入", "登录" }, true);

            if (navElement == null && !hasLogout)
            {
                //可能是出现了广告窗口,那么back关闭广告
                appAccess.ClickBackButton();
                Thread.Sleep(5000);
                //判断存在“立即加入”和“登录”按钮
                return(!appAccess.CheckCurrentPageContainText(new string[] { "立即加入", "登录" }, true));
            }
            else
            {
                return(!hasLogout);
            }
        }
Ejemplo n.º 4
0
        private bool CheckIsAnonymousUserPage(AndroidAppAccess appAccess)
        {
            int checkCount = 0;

            while (checkCount < 5)
            {
                try
                {
                    return(appAccess.CheckContainTextByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.TextView", new string[] { "该会员在您的人脉圈外" }, true));
                }
                catch (Exception ex)
                {
                    checkCount++;
                    Thread.Sleep(2000);
                }
            }

            this.RunPage.InvokeAppendLogText("无法判断是否是匿名用户,即检测'该会员在您的人脉圈外'是否存在不成功", LogLevelType.Error, true);
            return(true);
        }
Ejemplo n.º 5
0
        private string GetPersonLinkedinUrlFromElement(AndroidAppAccess appAccess, int swipeCount)
        {
            Thread.Sleep(2000);
            bool canRead = !this.CheckIsAnonymousUserPage(appAccess);

            if (canRead)
            {
                XmlElement rootXmlElement      = appAccess.GetXmlRootElement();
                XmlNode    containerXmlElement = rootXmlElement.SelectSingleNode("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.view.View/android.view.View/android.support.v7.widget.RecyclerView");

                XmlNodeList infoSectionXmlElements = containerXmlElement.SelectNodes("./android.widget.LinearLayout");
                foreach (XmlNode infoSectionXmlElement in infoSectionXmlElements)
                {
                    XmlNode sectionNameXmlElement = infoSectionXmlElement.SelectSingleNode("./android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.TextView");
                    if (sectionNameXmlElement != null && sectionNameXmlElement.Attributes["text"].Value == "联系信息")
                    {
                        XmlNode linkElement = infoSectionXmlElement.SelectSingleNode("./android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[2]/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.TextView[2]");
                        if (linkElement != null && linkElement.Attributes["text"].Value.Contains(".linkedin.com/"))
                        {
                            return(linkElement.Attributes["text"].Value.Trim());
                        }
                    }
                }

                if (swipeCount < 10)
                {
                    swipeCount++;
                    appAccess.Swipe(new Point(200, 900), new Point(200, 200), 1000);
                    return(this.GetPersonLinkedinUrlFromElement(appAccess, swipeCount));
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 6
0
        private bool GetProductInfo(AndroidAppAccess appAccess, AndroidElement productElement, XmlElement productXmlElement, List <Dictionary <String, string> > allShopProducts, Dictionary <string, string> allProductNames)
        {
            try
            {
                XmlElement nameXmlElement = (XmlElement)productXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jd.lib.jshop:id/product_item_name\"]");
                if (nameXmlElement != null)
                {
                    string productName = nameXmlElement.GetAttribute("text");
                    productName = productName.StartsWith("1 ") ? productName.Substring(2).Trim() : productName.Trim();
                    if (!allProductNames.ContainsKey(productName))
                    {
                        XmlElement priceXmlElement = (XmlElement)productXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jd.lib.jshop:id/product_item_jdPrice\"]");
                        if (priceXmlElement != null)
                        {
                            string price = priceXmlElement.GetAttribute("text");

                            XmlElement commentNumXmlElement = (XmlElement)productXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jd.lib.jshop:id/product_item_commentNumber\"]");
                            string     commentNum           = commentNumXmlElement == null ? "" : commentNumXmlElement.GetAttribute("text");

                            XmlElement goodMarkXmlElement = (XmlElement)productXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jd.lib.jshop:id/product_item_good\"]");
                            string     goodMark           = goodMarkXmlElement == null ? "" : goodMarkXmlElement.GetAttribute("text");

                            allProductNames.Add(productName, null);
                            Dictionary <string, string> shopInfo = new Dictionary <string, string>();
                            shopInfo.Add("productName", productName);
                            shopInfo.Add("commentNum", commentNum);
                            shopInfo.Add("price", price);
                            shopInfo.Add("goodMark", goodMark);
                            allShopProducts.Add(shopInfo);
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
Ejemplo n.º 7
0
        private bool GetShopInfo(AndroidAppAccess appAccess, AndroidElement shopElement, XmlElement shopXmlElement, List <Dictionary <String, string> > allKeywordShops, Dictionary <string, string> allShopNames)
        {
            try
            {
                XmlElement nameXmlElement = (XmlElement)shopXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jingdong.app.mall:id/b6n\"]");
                if (nameXmlElement != null)
                {
                    string name = nameXmlElement.GetAttribute("text");
                    if (!allShopNames.ContainsKey(name))
                    {
                        XmlElement subscribeXmlElement = (XmlElement)shopXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jingdong.app.mall:id/b6s\"]");
                        if (subscribeXmlElement != null)
                        {
                            string     subscribe      = subscribeXmlElement.GetAttribute("text");
                            XmlElement markXmlElement = (XmlElement)shopXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jingdong.app.mall:id/b6t\"]");
                            string     mark           = markXmlElement == null ? "" : markXmlElement.GetAttribute("text");

                            XmlElement jdSelfXmlElement = (XmlElement)shopXmlElement.SelectSingleNode("./descendant::android.widget.TextView[@resource-id=\"com.jingdong.app.mall:id/b6k\"]");
                            string     jdSelf           = jdSelfXmlElement == null ? "入驻" : "自营";

                            allShopNames.Add(name, null);
                            Dictionary <string, string> shopInfo = new Dictionary <string, string>();
                            shopInfo.Add("name", name);
                            shopInfo.Add("subscribe", subscribe);
                            shopInfo.Add("mark", mark);
                            shopInfo.Add("jdSelf", jdSelf);
                            allKeywordShops.Add(shopInfo);
                            return(true);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
            return(false);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 执行登出
        /// </summary>
        /// <param name="appAccess"></param>
        private void DoLogout(AndroidAppAccess appAccess)
        {
            AndroidElement navElement = GetNavElement(appAccess, true);
            AndroidElement myElement  = appAccess.GetElementByClassNameAndText("android.widget.TextView", "我", true, true, true);

            myElement.Click();

            //等待“我”的页面展示出来
            AndroidElement checkUserElment = appAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "谁看过我" }, true, false);

            if (checkUserElment != null)
            {
                appAccess.Swipe(new Point(200, 800), new Point(200, 100), 1000);
                AndroidElement personalSettingElement = appAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "个人设置" }, true, true);
                personalSettingElement.Click();
            }
            else
            {
                try
                {
                    AndroidElement toolElement = appAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.FrameLayout/android.support.v4.widget.DrawerLayout/android.view.View/android.widget.LinearLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.ImageView", true);
                    toolElement.Click();
                }
                catch (Exception ex)
                {
                    throw new Exception("无法打开个人设置页面", ex);
                }
            }

            appAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "邮箱地址" }, true, true);
            appAccess.Swipe(new Point(200, 800), new Point(200, 100), 1000);
            AndroidElement logoutElement = appAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "退出帐号" }, true, true);

            logoutElement.Click();

            appAccess.CheckCurrentPageContainText(new string[] { "立即加入", "登录" }, true, true);
        }
Ejemplo n.º 9
0
        private Dictionary <string, string> GetSkuInfo(AndroidAppAccess appAccess, string shopName, string shopWebPageUrl, AndroidElement skuElement, XmlElement skuXmlElement)
        {
            string         skuName     = "";
            string         pricePrefix = "";
            AndroidElement nameElement = (AndroidElement)appAccess.GetElementByIdNoWaiting(skuElement, "com.taobao.taobao:id/title", false);

            if (nameElement != null)
            {
                AndroidElement priceElement = (AndroidElement)appAccess.GetElementByIdNoWaiting(skuElement, "com.taobao.taobao:id/priceBlock", false);
                if (priceElement != null)
                {
                    XmlElement priceXmlElement = (XmlElement)skuXmlElement.SelectSingleNode("./android.view.View[@resource-id=\"com.taobao.taobao:id/priceBlock\"]");
                    if (priceXmlElement != null)
                    {
                        skuName = nameElement.Text;
                        string priceStr  = priceXmlElement.GetAttribute("content-desc").Trim();
                        int    yuanIndex = priceStr.IndexOf("元");
                        pricePrefix = priceStr.Substring(0, yuanIndex).Trim();
                    }
                }
            }

            if (skuName.Length > 0)
            {
                //判断此sku信息是否抓取完成
                string skuFilePath = this.GetSkuInfoLocalFilePath(shopName, skuName);
                Dictionary <string, string> skuInfo = null;
                if (File.Exists(skuFilePath))
                {
                    skuInfo = this.ReadSkuInfoFromLocalFile(skuFilePath);
                }
                else
                {
                    nameElement.Click();

                    string price          = "";
                    string transportFee   = "";
                    string monthSellCount = "";
                    string district       = "";
                    string commentCount   = "";

                    AndroidElement mainElement = appAccess.GetElementByXPath("//android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.RelativeLayout/android.widget.FrameLayout/android.widget.ScrollView/android.widget.LinearLayout/android.widget.ListView", true);

                    //价格
                    AndroidElement priceElement = appAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "¥" }, false, true);
                    price = priceElement.Text.Trim();

                    //快递费、月销量、地区
                    XmlElement  xmlRoot = appAccess.GetXmlRootElement();
                    XmlNodeList linearLayoutXmlElements = xmlRoot.SelectNodes("//android.widget.ListView[@resource-id=\"com.taobao.taobao:id/mainpage\"]/android.widget.LinearLayout");
                    XmlNodeList otherInfoXmlElements    = null;
                    foreach (XmlElement linearLayoutxmlElement in linearLayoutXmlElements)
                    {
                        XmlNodeList checkXmlElements = linearLayoutxmlElement.SelectNodes("./android.widget.TextView");
                        foreach (XmlElement checkXmlElement in checkXmlElements)
                        {
                            string checkText = checkXmlElement.GetAttribute("text");
                            if (checkText.Contains("快递:"))
                            {
                                otherInfoXmlElements = checkXmlElements;
                                break;
                            }
                        }
                        if (otherInfoXmlElements != null)
                        {
                            break;
                        }
                    }
                    if (otherInfoXmlElements != null)
                    {
                        foreach (XmlElement element in otherInfoXmlElements)
                        {
                            string text = element.GetAttribute("text").Trim();
                            if (text.Contains("快递"))
                            {
                                transportFee = text;
                            }
                            else if (text.Contains("月销"))
                            {
                                monthSellCount = text;
                            }
                            else
                            {
                                district = text;
                            }
                        }
                    }

                    //滚动屏幕,用来显示评论数
                    //appAccess.Swipe(new Point(100, 1000), new Point(100, 100), 2000);

                    try
                    {
                        AndroidElement commentElement = appAccess.GetElementById("com.taobao.taobao:id/detail_main_comment_count", true);
                        commentCount = commentElement.Text.Trim();
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("没有找到评论数元素, shopName = " + shopName + ", shopWebPageUrl = " + shopWebPageUrl + ", skuName = " + skuName, ex);
                    }

                    skuInfo = new Dictionary <string, string>();
                    skuInfo.Add("name", skuName);
                    skuInfo.Add("price", price);
                    skuInfo.Add("transportFee", transportFee);
                    skuInfo.Add("monthSellCount", monthSellCount);
                    skuInfo.Add("district", district);
                    skuInfo.Add("commentCount", commentCount);
                    this.SaveSkuInfoToLocalFile(skuFilePath, skuInfo);

                    appAccess.ClickBackButton();
                }
                return(skuInfo);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 10
0
        private bool GotoKeywordShopListPage(AndroidAppAccess appAccess, string keyword)
        {
            //点击后进入查询页面
            AndroidElement gotoInputElement = null;

            try
            {
                gotoInputElement = appAccess.GetElementById("com.jingdong.app.mall:id/a10", true);
            }
            catch (Exception ex)
            {
                AndroidElement adElement = appAccess.GetElementById("com.jingdong.app.mall:id/aqz", true);
                adElement.Click();
                gotoInputElement = appAccess.GetElementById("com.jingdong.app.mall:id/a10", true);
            }

            gotoInputElement.Click();

            //录入店铺keyword
            AndroidElement inputKeywordElement = appAccess.GetElementById("com.jd.lib.search:id/search_text", true);

            inputKeywordElement.SendKeys(keyword);

            //店铺查询按钮,点击后应该进入店铺列表页面
            AndroidElement searchShopBtnElement = appAccess.GetElementById("com.jd.lib.search:id/home_auto_complete_item_container", true);

            searchShopBtnElement.Click();

            AndroidElement shopListContainerElement = appAccess.GetElementByIdNoWaiting("com.jingdong.app.mall:id/b6b", false);
            int            noAlertTime = 0;

            while (shopListContainerElement == null)
            {
                AndroidElement reSearchShopBtnElement = appAccess.GetElementById("com.jingdong.app.mall:id/ad0", true);
                reSearchShopBtnElement.Click();
                Thread.Sleep(3000);
                noAlertTime++;
                shopListContainerElement = appAccess.GetElementByIdNoWaiting("com.jingdong.app.mall:id/b6b", false);
                if (noAlertTime > 3)
                {
                    break;
                }
            }

            if (shopListContainerElement == null)
            {
                AndroidElement noShopAlertElement = appAccess.GetElementByIdNoWaiting("com.jingdong.app.mall:id/b4x", false);
                if (noShopAlertElement != null)
                {
                    return(false);
                }
                else
                {
                    throw new Exception("无法获取到店铺列表, keyword = " + keyword);
                }
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 11
0
        public override void GetDataByOtherAccessType(Dictionary <string, string> listRow)
        {
            string keyWords      = listRow["keyWords"];
            string loginName     = listRow["loginName"];
            string loginPassword = listRow["loginPassword"];

            string fileName = "_" + keyWords + "_" + loginName;
            List <Dictionary <string, string> > personInfos = this.RunPage.TryGetInfoFromMiddleFile(fileName, new string[] { "personName", "personUrl" });

            if (personInfos == null)
            {
                this.RunPage.InvokeAppendLogText("开始使用APP搜索相关人员, 关键词为'" + keyWords + "'", LogLevelType.System, true);

                AndroidAppAccess appAccess = null;

                try
                {
                    this.RunPage.InvokeAppendLogText("开始连接手机APP", LogLevelType.System, true);
                    appAccess = this.InitAppAccess();
                    this.RunPage.InvokeAppendLogText("连接手机APP成功", LogLevelType.System, true);

                    bool needLogout = false;

                    try
                    {
                        this.RunPage.InvokeAppendLogText("检测是否需要登出", LogLevelType.System, true);
                        needLogout = this.CheckNeedLogout(appAccess);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("检查是否需要登出出错.", ex);
                    }
                    if (needLogout)
                    {
                        try
                        {
                            this.RunPage.InvokeAppendLogText("开始登出", LogLevelType.System, true);
                            this.DoLogout(appAccess);
                            this.RunPage.InvokeAppendLogText("已经登出", LogLevelType.System, true);
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("登出失败.", ex);
                        }
                    }

                    try
                    {
                        this.RunPage.InvokeAppendLogText("开始登录", LogLevelType.System, true);
                        this.DoLogin(appAccess, loginName, loginPassword);
                        this.RunPage.InvokeAppendLogText("已经登录", LogLevelType.System, true);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("登录失败.", ex);
                    }

                    try
                    {
                        personInfos = this.SearchPersonByKeyWord(appAccess, keyWords);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("在app中根据关键字抓取出错, keyWords = " + keyWords);
                    }

                    this.RunPage.SaveInfoToMiddleFile(fileName, new string[] { "personName", "personUrl" }, personInfos);
                    this.RunPage.InvokeAppendLogText("完成使用手机APP搜索关键词'" + keyWords + "", LogLevelType.System, true);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (appAccess != null)
                    {
                        this.CloseAppAccess(appAccess);
                    }
                }
            }

            try
            {
                string checkedRelatedPersonInfosResultFilePath = this.RunPage.GetFilePath("_SearchResult_LinkedinApp_" + loginName + "_" + keyWords + ".xlsx", this.RunPage.GetExportDir());
                if (!File.Exists(checkedRelatedPersonInfosResultFilePath))
                {
                    this.RunPage.InvokeAppendLogText("登录Linkedin系统", LogLevelType.System, true);
                    LoginLinkedin.LoginByRandomUser(this.RunPage, this.LinkedinLoginPageUrl, this.LinkedinLoginSucceedCheckUrl);
                    this.RunPage.InvokeAppendLogText("已登录Linkedin系统", LogLevelType.System, true);

                    this.RunPage.InvokeAppendLogText("根据个人页面地址(人员列表是从手机APP搜索到的,关键词为'" + keyWords + "'),从Linkedin网页版获取个人信息", LogLevelType.System, true);
                    string personPageInfosWithJustDownloadMarkFileName = "_" + loginName + "_" + keyWords + "_personPageInfosWithJustDownloadMark";
                    //读取历史生成的个人网页网址
                    List <Dictionary <string, string> > allPersonPageInfosWithJustDownloadMark = this.RunPage.TryGetInfoFromMiddleFile(personPageInfosWithJustDownloadMarkFileName, new string[] { "personUrl", "personName", "isJustDownload" });
                    if (allPersonPageInfosWithJustDownloadMark == null)
                    {
                        allPersonPageInfosWithJustDownloadMark = ProcessPersonPage.GetAllPersonPages(this.RunPage, personInfos, loginName, loginPassword);
                        this.RunPage.SaveInfoToMiddleFile(personPageInfosWithJustDownloadMarkFileName, new string[] { "personUrl", "personName", "isJustDownload" }, allPersonPageInfosWithJustDownloadMark);
                    }

                    string personInfosFilePath = this.RunPage.GetFilePath("_SearchResult_LinkedinApp_" + loginName + "_" + keyWords + ".xlsx", this.RunPage.GetExportDir());
                    if (!File.Exists(personInfosFilePath))
                    {
                        List <Dictionary <string, string> > personInfoList = ProcessPersonPage.GetPersonInfoFromLocalPages(this.RunPage, allPersonPageInfosWithJustDownloadMark, false, null);
                        ProcessPersonPage.SavePersonInfoToFile(this.RunPage, personInfoList, personInfosFilePath);
                    }
                    this.RunPage.InvokeAppendLogText("完成获取并处理个人页面(人员列表是从手机APP搜索到的,关键词为'" + keyWords + "')", LogLevelType.System, true);

                    /*
                     * this.RunPage.InvokeAppendLogText("从已爬取到的页面中,找到'看过本页的会员还看了'栏目里的个人信息,递归获取", LogLevelType.System, true);
                     * string checkedRelatedPersonIdsFileName = "_" + keyWords + "_" + loginName + "_CheckedRelated";
                     * List<Dictionary<string, string>> allCheckedRelatedIds = this.RunPage.TryGetInfoFromMiddleFile(checkedRelatedPersonIdsFileName, new string[] { "checkedRelatedPersonInfoId", "levelCount" });
                     * if (allCheckedRelatedIds == null)
                     * {
                     *  allCheckedRelatedIds = new List<Dictionary<string, string>>();
                     *  Dictionary<string, string> allRelatedPersonUrlInfos = new Dictionary<string, string>();
                     *  ProcessPersonPage.GetRelatedPersonInfos(this.RunPage, allPersonPageInfosWithJustDownloadMark, allRelatedPersonUrlInfos, allCheckedRelatedIds, keyWords);
                     *  this.RunPage.SaveInfoToMiddleFile(checkedRelatedPersonIdsFileName, new string[] { "checkedRelatedPersonInfoId", "levelCount" }, allCheckedRelatedIds);
                     * }
                     *
                     * this.RunPage.InvokeAppendLogText("从已爬取到的页面中,找到'看过本页的会员还看了'栏目里的个人信息", LogLevelType.System, true);
                     * string checkedRelatedPersonUrlsFileName = "_" + loginName + "_" + keyWords + "_personUrl_CheckedRelated";
                     * List<Dictionary<string, string>> allCheckAllCheckedRelatedUrls = this.RunPage.TryGetInfoFromMiddleFile(checkedRelatedPersonUrlsFileName, new string[] { "personUrl", "personName" });
                     * if (allCheckAllCheckedRelatedUrls == null)
                     * {
                     *  allCheckAllCheckedRelatedUrls = ProcessPersonPage.GetAllPersonPages(this.RunPage, allCheckedRelatedIds);
                     * }
                     *
                     * List<string> checkRelatedPersonPageIds = new List<string>();
                     * foreach (Dictionary<string, string> checkedRelatedId in allCheckedRelatedIds)
                     * {
                     *  string checkedRelatedPersonInfoId = checkedRelatedId["checkedRelatedPersonInfoId"];
                     *  checkRelatedPersonPageIds.Add(checkedRelatedPersonInfoId);
                     * }
                     * List<Dictionary<string, string>> relatedPersonInfoList = ProcessPersonPage.GetPersonInfoFromLocalPages(this.RunPage, allCheckAllCheckedRelatedUrls, false, null);
                     * ProcessPersonPage.SavePersonInfoToFile(this.RunPage, relatedPersonInfoList, checkedRelatedPersonInfosResultFilePath);
                     */

                    this.RunPage.InvokeAppendLogText("完成递归爬取到关键词'" + keyWords + "'相关的所有的'看过本页的会员还看了'", LogLevelType.System, true);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("通过网页获取/处理个人信息出错", ex);
            }
        }
Ejemplo n.º 12
0
        private AndroidElement GetNextPersonElement(AndroidAppAccess appAccess, Dictionary <string, string> personSimpleInfos, int noneNewCount)
        {
            AndroidElement listContainerElement = appAccess.GetElementByClassNameAndIndex("android.support.v7.widget.RecyclerView", 0, true);

            if (!appAccess.CheckElementContainText(listContainerElement, new string[] { "没有找到结果" }, true))
            {
                ReadOnlyCollection <AndroidElement> listElements = appAccess.GetElementsByClassName(listContainerElement, "android.widget.FrameLayout", false);
                if (listElements != null)
                {
                    for (int i = 0; i < listElements.Count; i++)
                    {
                        AppiumWebElement listRElement = listElements[i].FindElementByClassName("android.widget.RelativeLayout");
                        if (listRElement != null)
                        {
                            ReadOnlyCollection <AppiumWebElement> listLElements = listRElement.FindElementsByClassName("android.widget.LinearLayout");
                            if (listLElements != null && listLElements.Count > 0)
                            {
                                string elementText = this.GetListPersonElementText(appAccess, (AndroidElement)listLElements[0]);
                                if (elementText == null)
                                {
                                    //获取个人信息出错,可能是个人信息展示不完全造成的,那么翻页吧
                                    break;
                                }
                                else if (elementText.Contains("领英会员"))
                                {
                                    continue;
                                }
                                else if (!personSimpleInfos.ContainsKey(elementText))
                                {
                                    personSimpleInfos.Add(elementText, null);
                                    return((AndroidElement)listLElements[0]);
                                }
                            }
                        }
                    }

                    if (noneNewCount < 3)
                    {
                        noneNewCount++;
                        //滑动翻页
                        appAccess.Swipe(new Point(100, 700), new Point(100, 200), 500);
                        Thread.Sleep(500);
                        return(this.GetNextPersonElement(appAccess, personSimpleInfos, noneNewCount));
                    }
                    else
                    {
                        //滑动翻页了3次,仍然没有新的,那么就认为真的没有新的了
                        return(null);
                    }
                }
                else
                {
                    //没有匹配的结果
                    return(null);
                }
            }
            else
            {
                //没有匹配的结果
                return(null);
            }
        }
Ejemplo n.º 13
0
        private string GetNameByListPersonElement(AndroidAppAccess appAccess, AndroidElement listLElement)
        {
            AppiumWebElement nameElement = listLElement.FindElementByClassName("android.widget.LinearLayout").FindElementByClassName("android.widget.TextView");

            return(nameElement == null ? null : nameElement.Text);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 使用某关键词查询
        /// </summary>
        /// <param name="appAccess"></param>
        private List <Dictionary <string, string> > SearchPersonByKeyWord(AndroidAppAccess appAccess, string keyWords)
        {
            //存储查询到的人员类别
            List <Dictionary <string, string> > personList = new List <Dictionary <string, string> >();

            AndroidElement searchElement = appAccess.GetElementByClassNameAndText("android.widget.TextView", new string[] { "搜索用户、职位及其他内容" }, true, true);

            searchElement.Click();
            Thread.Sleep(5000);
            searchElement.SendKeys(keyWords);
            Thread.Sleep(5000);
            appAccess.SendKeyEvent(66);
            Thread.Sleep(5000);

            Dictionary <string, string> personSimpleInfos = new Dictionary <string, string>();
            AndroidElement personListElement = null;

            try
            {
                personListElement = this.GetNextPersonElement(appAccess, personSimpleInfos, 0);
            }
            catch (Exception ex)
            {
                throw new Exception("在app中根据关键字查询,获取查询结果列表中第一位会员信息出错", ex);
            }

            Dictionary <string, string> personUrlDic = new Dictionary <string, string>();

            while (personListElement != null)
            {
                //点击列表项,跳转到个人页面,记录个人信息
                string personName = this.GetNameByListPersonElement(appAccess, personListElement);
                try
                {
                    string personUrl = this.GetPersonLinkedinUrlFromPersonPage(appAccess, personListElement, keyWords);

                    if (personUrl == null)
                    {
                        this.RunPage.InvokeAppendLogText("无法从app的个人页面里找到linkedin个人网址", LogLevelType.System, true);
                    }
                    else
                    {
                        if (!personUrlDic.ContainsKey(personUrl))
                        {
                            personUrlDic.Add(personUrl, null);

                            Dictionary <string, string> personInfo = new Dictionary <string, string>();
                            personInfo.Add("personName", personName);
                            personInfo.Add("personUrl", personUrl);
                            personList.Add(personInfo);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("使用APP抓取的个人信息出错, personName = " + personName, ex);
                }

                try
                {
                    personListElement = this.GetNextPersonElement(appAccess, personSimpleInfos, 0);
                }
                catch (Exception ex)
                {
                    throw new Exception("获取下一位会员信息出错, personName = " + personName, ex);
                }
            }
            return(personList);
        }