Ben PhpQuery ile bazı html ayrıştırmak çalışıyorum, ama bu benim için kolay değil ...
Ben bir dizi sadece URL (href tag) ayıklamak gerekir ama çalışmıyor.
Sadece örnek amaçlar için bu kodu bakın:
$doc = phpQuery::newDocumentHTML('<div align = "left" style="background-color:#FFFFFF;border:1px solid #C3D9FF"> </p>
<table cellPadding="2" cellSpacing="0" width="100%" height="60" style="border-collapse: collapse; ">
<tr>
<td align="left" width="531" height="20"><small>
<strong>
<a href="/1153414/">
<font style="FONT-SIZE: 13px; LINE-HEIGHT: 14px">Industrial</font><a/> </a></small></strong>
</td>
</tr>
<tr>
<td align="left" vAlign="top" width="100%" height="1">
<table align="left" border="0" cellPadding="0" cellSpacing="0" width="736">
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">
Data:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> 4-1-2011 </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Zona:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Castelo Branco</font></td>
</tr>
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Categoria:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Indústria / Produção </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Empresa:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Isotransfo, Unipessoal LDA</font></td>
</tr>
</table>
</td>
</tr>
</table>
</p>
<table cellPadding="2" cellSpacing="0" width="100%" height="60" style="border-collapse: collapse; ">
<tr>
<td align="left" width="531" height="20"><small>
<strong>
<a href="/1153399/">
<font style="FONT-SIZE: 13px; LINE-HEIGHT: 14px">Admite-se<a/> </a> </font></small></strong>
</td>
</tr>
<tr>
<td align="left" vAlign="top" width="100%" height="1">
<table align="left" border="0" cellPadding="0" cellSpacing="0" width="736">
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">
Data:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> 4-1-2011 </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Zona:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Castelo Branco</font></td>
</tr>
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Categoria:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Indústria / Produção </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Empresa:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Isotransfo, Unipessoal LDA</font></td>
</tr>
</table>
</td>
</tr>
</table>
</p>
<table cellPadding="2" cellSpacing="0" width="100%" height="60" style="border-collapse: collapse; ">
<tr>
<td align="left" width="531" height="20"><small><font face="Arial">
<strong>
<a href="/1153280/">
<font style="FONT-SIZE: 13px; LINE-HEIGHT: 14px">Precisa-se</font><a/> </a> </font></small></strong>
</td>
</tr>
<tr>
<td align="left" vAlign="top" width="100%" height="1">
<table align="left" border="0" cellPadding="0" cellSpacing="0" width="736">
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">
Data:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> 4-1-2011 </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Zona:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> ( Todas as Zonas )</font></td>
</tr>
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Categoria:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Saúde / Medicina / Enfermagem </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Empresa:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Emprego Radiologia</font></td>
</tr>
</table>
</td>
</tr>
</table>
</p>
<table cellPadding="2" cellSpacing="0" width="100%" height="60" style="border-collapse: collapse; ">
<tr>
<td align="left" width="531" height="20"><small><font face="Arial">
<strong>
<a href="/1152665/">
<font style="FONT-SIZE: 13px; LINE-HEIGHT: 14px">Operadores</font><a/> </a> </font></small></strong>
</td>
</tr>
<tr>
<td align="left" vAlign="top" width="100%" height="1">
<table align="left" border="0" cellPadding="0" cellSpacing="0" width="736">
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">
Data:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> 4-1-2011 </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Zona:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Viseu</font></td>
</tr>
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Categoria:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Lojas / Comércio / Balcão </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Empresa:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Dia Portugal Supermercados - Soc. Unip., Lda.</font></td>
</tr>
</table>
</td>
</tr>
</table>
</p>
<table cellPadding="2" cellSpacing="0" width="100%" height="60" style="border-collapse: collapse; ">
<tr>
<td align="left" width="531" height="20"><small><font face="Arial">
<strong>
<a href="/1153524/">
<font style="FONT-SIZE: 13px; LINE-HEIGHT: 14px">Responsável</font><a/> </a> </font></small></strong>
</td>
</tr>
<tr>
<td align="left" vAlign="top" width="100%" height="1">
<table align="left" border="0" cellPadding="0" cellSpacing="0" width="736">
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">
Data:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> 4-1-2011 </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Zona:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Santarem</font></td>
</tr>
<tr>
<td align="left" vAlign="top" width="67">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Categoria:</font></strong></td>
<td align="left" vAlign="top" width="150">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> Comercial / Vendas </font></td>
<td align="left" vAlign="top" width="59">
<font color="#000000" face="Arial" size="2">
<strong style="FONT-SIZE: 11px; LINE-HEIGHT: 14px; font-weight:400">
<font face="Arial" color="#333333" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px">Empresa:</font></strong></td>
<td align="left" vAlign="top" width="473">
<font face="Arial" style="FONT-SIZE: 11px; LINE-HEIGHT: 14px"> ALDI Supermercados Lda.</font></td>
</tr>
</table>
</td>
</tr>
</table>
</div>');
//echo $doc['div table a']->attr('href');
foreach ($doc['div table a'] as $a) {
$hrefs[] .= pq($a)->attr('href');
}
print_r ($hrefs);
Ben sadece href url benim olsun, ve o ok feryat kodunu echo eğer:
echo $doc['div table a']->attr('href');
Ben foreach deyimini çalıştırın bazı null değerleri ile bir dizi var:
foreach ($doc['div table a'] as $a) {
$hrefs[] .= pq($a)->attr('href');
}
print_r ($hrefs);
I got dizidir:
Array (
[0] => /1153414/
[1] =>
[2] => /1153399/
[3] =>
[4] => /1153280/
[5] =>
[6] => /1152665/
[7] =>
[8] => /1153524/
[9] =>
)
Nasıl böyle bir dizi oluşturabilirsiniz:
Array (
[0] => /1153414/
[1] => /1153399/
[2] => /1153280/
[3] => /1152665/
[4] => /1153524/
)
Bana bazı ipuçları verebilir, ben mutluluk duyacağız.
Maalesef benim kötü İngilizce
Saygılarımızla,