我想从每篇文章(表格)中获取 tr 2, td 4, first a 上的文本,我不能链接到文本,因为当我print_r
没有得到任何显示回来时。
// table 1
<table class="articles">
<tbody>
<tr>some text here maybe tags</tr>
<tr>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td><a href="link.html">WANT TO GET THIS TEXT</a></td>
</tr>
</tbody>
</table>
// table 2
<table class="articles">
<tbody>
<tr>some text here maybe tags</tr>
<tr>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td><a href="link.html">WANT TO GET THIS TEXT</a></td>
</tr>
</tbody>
</table>
// more tables etc.
<table class="articles">
<tbody>
<tr>some text here maybe tags</tr>
<tr>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td> some text here maybe tags </td>
<td><a href="link.html">WANT TO GET THIS TEXT</a></td>
</tr>
</tbody>
</table>
我的 phpQuery 代码没有错误,但什么也没有显示,我不确定我做错了什么。
<?php
require "phpQuery/phpQuery-onefile.php";
// Load betting page
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://example.net/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
curl_close($ch);
// Create phpQuery document with returned HTML
$doc = phpQuery::newDocument($html);
$articleDate = array();
$surroundingTheArticles = $doc->find('table.articles');
foreach( $surroundingTheArticles as $eachArticle)
{
// get table rows
$articleDate[] .= pq($eachArticle)->find('tbody:eq(0) tr:eq(1) td:eq(4)')->text(); // maybe first:a or something - don't know
}
print_r($articleDate[1]);
// find a way to print all article dates
?>