2017-03-10 68 views
-1

在java中运行phantomjs让我头疼。当我运行程序和getpagesource时,我能够提取a-> src属性的ul-> li文本,但不能在SPAN标签内。这可能是由于掩盖或不正确的CSS。 JS脚本是角度的。selenium phantomjs span标签不显示

我选择控制台输出后,我打电话driver.getPageSource()是(通知物业地址为空):

 <div class="propertylist-property-details col-lg-6"> 
      <a href="/property-detail/gblhrdlad152749"> 
       <span class="property-name ng-binding" ng-bind="data.AddressLine1"></span> 
       <span class="property-address ng-binding" ng-bind="data.AddressLine2"></span> 
      </a> 


       <!-- ngIf: --> 

      <span class="property-bullets"> 
       <ul> 
         <li>- Grade II listed facade </li> 
         <li>- Exposed concrete beams </li> 
         <li>- Italian kitchens </li> 
         <li>- Underfloor heating and comfort cooling </li> 
         <li>1054 Sq.Feet (97.92 Sq.Metres) </li> 
       </ul> 
      </span> 
     </div> 

我的Java代码如下:

 public static synchronized void testPhantomDriver() throws Exception { 

    DesiredCapabilities caps = new DesiredCapabilities(); 
    caps.setJavascriptEnabled(true); 
    caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\location of \\phantomjs.exe"); 
    String oldpage=""; String newpage="";  
    WebDriver driver = new PhantomJSDriver(caps); 
    try{ 
    driver.get("http://search.savills.com/property-detail/gbcsrdlad140551#/r/list/property-for-sale%252Fengland%252Fbristol%252Fbristol%252Fbs1%252Fgbp"); 



    WebElement menu = driver.findElement(By.xpath("//*[@id=\"ctl_GRS_PT_ND\"]")); // the trigger event element 

    Actions build = new Actions(driver); // ActionBuider 
    build.moveToElement(menu).build().perform(); // perform hover mouse over the needed element to triger visibility 
    build.click(); 
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
    String pageSource = driver.getPageSource(); 

     driver.findElement(By.id("ViewAll")).click(); 
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
     System.out.println("clicked"); 
     //driver = scrollToBottom(driver, 2000); 
     try{ 
      System.out.println("waiting"); 
      driver.wait(4000); 
     }catch(InterruptedException ie){ 
      System.out.println("iexception: " + ie); 
     } 
     System.out.println(driver.getPageSource());  
}catch(Exception exp){ 
    System.out.println("exception:" + exp); 
    driver.close(); 
    driver.quit(); 
} 
    driver.close(); 
    driver.quit(); 
} 
/** 
* Main method 
*/ 
public static void main(String[] args) { 
    try { 
     // run webdriver 
     testPhantomDriver(); 
    } catch (Exception ex) { 
     System.out.println("exception"); 
    } 
} 

一些解决方案,我有一直在想你可能会帮忙? (1)加载iframe(2)或等待完成页面加载。我尝试使用connect(url).get()在Jsoup中读取页面,但隐藏的可见性仍然存在。

任何帮助,将不胜感激。

回答

0

问题解决

尝试firefoxdriver和chromedriver代替phantomjs.exe的。使用更多的内存,但至少可以获得所有数据。