使用selenium查找代码中的值

使用selenium查找代码中的值,selenium,Selenium,我需要打印facebook账号的好友列表,这些都在代码中。我正在使用java、webdriver、eclipse。那我该怎么做呢。。? 我的代码是: hc_location=friends_tab"> <div class="clearfix _42ef"> <div class="_6a rfloat _ohf"> <div class="uiProfileBlockContent"> <div class="_6a"> <div c

我需要打印facebook账号的好友列表,这些都在代码中。我正在使用java、webdriver、eclipse。那我该怎么做呢。。? 我的代码是:

hc_location=friends_tab">
<div class="clearfix _42ef">
<div class="_6a rfloat _ohf">
<div class="uiProfileBlockContent">
<div class="_6a">
<div class="_6a _6b" style="height:100px"/>
<div class="_6a _6b">
<div class="fsl fwb fcb">
<a data-hovercard="/ajax/hovercard/user.php?id=100004354923588&extragetparams=%7B%22hc_location%22%3A%22friends_tab%22%7D" data-gt="{"engagement":{"eng_type":"1","eng_src":"2","eng_tid":"100004354923588","eng_data":[]},"coeff2_registry_key":"0406","coeff2_info":"AatFZB3bSKV1-v1-TR2ok-dPAbN9rzl_3kU0pGsa25fiWaVHx5-bjHLWKDd3viMwgv1yaRLvlMdX3-X03tbhtjEZ","coeff2_action":"1","coeff2_pv_signature":"738277089"}" href="https://www.facebook.com/sivaramakrishna.churukuri?fref=pb&hc_location=friends_tab">Sivaramakrishna Churukuri</a>
</div>
<a class="uiLinkSubtle" data-gt="{"coeff2_registry_key":"0406","coeff2_info":"AauP9VE6r6RJg9RklXss8Ij7rBBpi8gQXqOJbBK3dhvJV9-qk6TEr1oJklIPahLAfMkkWVB_SIlPbQ6vlwDJIe13","coeff2_action":"13","coeff2_pv_signature":"738277089"}" href="https://www.facebook.com/sivaramakrishna.churukuri/friends">103 friends</a>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="_698">
<div class="clearfix _5qo4">
<a class="_5q6s _8o _8t lfloat _ohe" data-hovercard="/ajax/hovercard/user.php?id=100003212947042&extragetparams=%7B%22hc_location%22%3A%22friends_tab%22%7D" aria-hidden="true" tabindex="-1" href="https://www.facebook.com/kamesh.peri.5?fref=pb&hc_location=friends_tab">
<div class="clearfix _42ef">
<div class="_6a rfloat _ohf">
<div class="uiProfileBlockContent">
<div class="_6a">
<div class="_6a _6b" style="height:100px"/>
<div class="_6a _6b">
<div class="fsl fwb fcb">
<a data-hovercard="/ajax/hovercard/user.php?id=100003212947042&extragetparams=%7B%22hc_location%22%3A%22friends_tab%22%7D" data-gt="{"engagement":{"eng_type":"1","eng_src":"2","eng_tid":"100003212947042","eng_data":[]},"coeff2_registry_key":"0406","coeff2_info":"AauBaMRFF-E1ITEW9Rva9NO6xU67IbSuJZEgYIzHEB4CVZ_e6MM2fHCqF75opZvYnSlnHSOqYQ3EaZucFsMq6WMd","coeff2_action":"1","coeff2_pv_signature":"738277089"}" href="https://www.facebook.com/kamesh.peri.5?fref=pb&hc_location=friends_tab">Kamesh Peri</a>
</div>
<a class="uiLinkSubtle" data-gt="{"coeff2_registry_key":"0406","coeff2_info":"Aat-c_R0rmMkazYv1tQfMWB254d055vp_28IHeIbPNodi5AgjkwSKK0gxoikjPCHdstPnIZgBGM4DLQexsa3ctZ5","coeff2_action":"13","coeff2_pv_signature":"738277089"}" href="https://www.facebook.com/kamesh.peri.5/friends">374 friends</a>
</div>
</div>
</div>
</div>
</div>
</li>
<li class="_698">
<div class="clearfix _5qo4">
<a class="_5q6s _8o _8t lfloat _ohe" data-hovercard="/ajax/hovercard/user.php?id=678773097&extragetparams=%7B%22hc_location%22%3A%22friends_tab%22%7D" aria-hidden="true" tabindex="-1" href="https://www.facebook.com/rchalasani?fref=pb&hc_location=friends_tab">
<div class="clearfix _42ef">
<div class="_6a rfloat _ohf">
<div class="uiProfileBlockContent">
<div class="_6a">
<div class="_6a _6b" style="height:100px"/>
<div class="_6a _6b">
<div class="fsl fwb fcb">
<a data-hovercard="/ajax/hovercard/user.php?id=678773097&extragetparams=%7B%22hc_location%22%3A%22friends_tab%22%7D" data-gt="{"engagement":{"eng_type":"1","eng_src":"2","eng_tid":"678773097","eng_data":[]},"coeff2_registry_key":"0406","coeff2_info":"AasX8OsfTavfyAhEpE-iOv9PuaD2vgAhBs9ByrQ72VN1TWGanfz8Cc6UlLt7hsMf-Js","coeff2_action":"1","coeff2_pv_signature":"738277089"}" href="https://www.facebook.com/rchalasani?fref=pb&hc_location=friends_tab">Rama Chalasani</a>
</div>
<a class="uiLinkSubtle" role="button" rel="dialog" href="/browse/mutual_friends/?uid=678773097" ajaxify="/ajax/browser/dialog/mutual_friends/?uid=678773097" data-tooltip-uri="/ajax/mutual_friends/tooltip.php?friend_id=678773097" data-hover="tooltip">24 mutual friends</a>
hc\u location=friends\u选项卡”>

  • 我需要印刷《西瓦拉玛克里希纳·丘鲁库里》、《卡迈什·佩里》、《拉玛·查拉萨尼》,这些都在

    <a></a>
    
    
    
    标签

    提前谢谢

    我试过这个

    driver.findElement(By.id("email")).sendKeys("smallfishhh4@gmail.com");
            driver.findElement(By.id("pass")).clear();
            driver.findElement(By.id("pass")).sendKeys("password");
           // driver.findElement(By.id("u_0_n")).click();
            driver.findElement(By.xpath("//label[@id='loginbutton']/input")).click();
            driver.findElement(By.className("headerTinymanName")).click();
            driver.findElement(By.xpath("//a[@data-medley-id='pagelet_timeline_medley_friends']")).click();
           // List<WebElement> ele = driver.findElement(By.className("fsl fwb fcb"));
    
    
            List<WebElement> allNames = driver.findElements(By.xpath("//div[@class='fsl fwb fcb']/a"));
            //List<WebElement> allNames = driver.findElements(By.xpath("//div[@class='uiProfileBlockContent']/a"));
            int num = driver.findElements(By.xpath("//ul")).size();
            System.out.println(num);
            System.out.println(allNames.size());
    
            for(int j=0; j<num; j++){
            for(int i=0;i<allNames.size();i++){
                System.out.println(allNames.get(i).getText());
                names = names+allNames.get(i).getText();
            }
            }       
    
    driver.findElement(通过.id(“电子邮件”)).sendKeys(“smallfishhh4@gmail.com");
    driver.findElement(By.id(“pass”)).clear();
    driver.findElement(By.id(“pass”)).sendKeys(“密码”);
    //driver.findElement(By.id(“u_0_n”))。单击();
    findElement(By.xpath(“//label[@id='loginbutton']]/input”)。单击();
    driver.findElement(By.className(“headerTinymanName”)。单击();
    findElement(By.xpath(“//a[@data-medley-id='pagelet\u timeline\u-medley\u-friends']))。单击();
    //List ele=driver.findElement(By.className(“fsl-fwb-fcb”);
    列出所有名称=driver.findElements(By.xpath(“//div[@class='fsl fwb fcb']/a”);
    //List allNames=driver.findelelements(By.xpath(“//div[@class='uiProfileBlockContent']/a”);
    int num=driver.findElements(By.xpath(“//ul”).size();
    系统输出打印项数(num);
    System.out.println(allNames.size());
    
    对于(int j=0;jGet friend list using Selenium)来说,使用Selenium是网络抓取,您不应该这样做,这是非法的。相反,使用Java的graph api来实现您的目标。下面是一个示例。您可以使用的另一个选项是RestFB()

    public void getIds(){
                Session session = Session.getActiveSession();
                String query = "select uid from user where uid in (select uid2 from friend where uid1 = me())";
                Bundle params = new Bundle();
                params.putString("q", query);
                Request request = new Request(session, "/me/friends", params, HttpMethod.GET, new Request.Callback() {
    
                            @Override
                            public void onCompleted(Response response) {
    
                                Log.d("Id's :", "Response = "+response);
                            }
                        });
                Request.executeBatchAsync(request); 
            }