2014-03-27 4 views
-2

코드에있는 페이스 북 계정의 친구 목록의 이름을 인쇄해야합니다. java, webdriver, eclipse를 사용하고 있습니다. 그래서 내가 어떻게 할 수 있니? ..? 내 코드입니다 : 내가셀렌을 사용하여 코드에서 값을 찾으십시오.

<a></a> 

태그 사전에

덕분에 Sivaramakrishna Churukuri, Kamesh 요정, 라마 Chalasani를 인쇄해야

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> 

.

나는 셀레늄 웹 스크래핑이다 사용이

driver.findElement(By.id("email")).sendKeys("[email protected]"); 
     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(); 
     } 
     }  

답변

0

받기 친구 목록을 시도하고 당신은 그 불법을 그렇게해서는 안된다. 대신 Java로 그래프 API를 사용하여 목표를 달성하십시오. 아래는 하나의 예입니다. 사용할 수있는 또 다른 옵션은 RestFB (http://restfb.com/legacy-rest-api.html)

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); 
     } 
입니다.
관련 문제