2013-11-26 33 views
1

你好朋友, 我想獲取td部分包含的所有表格信息。 我曾嘗試這樣的代碼:表使用硒webdriver PHP解析?

$host = 'http://localhost:4444/wd/hub'; // this is the default 
$capabilities = array(WebDriverCapabilityType::BROWSER_NAME => 'firefox'); 
$driver = RemoteWebDriver::create($host, $capabilities,1000); 

$results = $driver->findElements(WebDriverBy::cssSelector('table #listbody tr')); 

for($i=0;$i<count($results);$i++) 
{ 
    echo $driver->findElement(WebDriverBy::className('rank'))->getext(); 
    sleep(3); 
} 

我的結構是這樣的:

<table id="listbody"> 
    <tr> 


    <td class="rank">1</td> 
     <td class="company"><a href="/companies/icbc/" class="exit_trigger_set"> 
<img alt="" src="http://i.forbesimg.com/media/lists/companies/icbc_50x50.jpg"> 
      <h3>ICBC</h3></a> 
     </td> 
     <td>China</td> 
     <td class="nowrap">$134.8 B</td> 
     <td class="nowrap">$37.8 B</td> 
     <td class="nowrap">$2,813.5 B</td> 
     <td class="nowrap">$237.3 B</td> 
    </tr> 
</table> 

回答

1

變化

echo $driver->findElement(WebDriverBy::className('rank'))->getext(); 

echo $results[$i]->findElement(WebDriverBy::className('rank'))->getext(); 
+0

:非常感謝sir.Is有什麼琳達視頻教程或任何其他資源,我可以真正開始使用PHP的硒。 –