Я хотел бы получить текст по tr 2, td 4, first a, из каждой статьи (таблицы), я не должен ссылаться на текст справа как когда я print_r
Я ничего не возвращаю назад.Как получить данные из таблицы, используя phpQuery в цикле foreach
// 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
?>
вы можете редактировать в массиве, который возвращается в print_r(), который будет определять, как вам нужно, чтобы цикл, или цикл в цикле, если это необходимо. –
ничего не отображает –