메신저 간단한 HTML 돔 파서를 사용하여 HTML 문자열에서 일부 데이터를 스크랩합니다.
난이 대구 시도
배열 요소로서 특정 CSS 클래스를 가진 테이블에서 각 TD를 TD의 값을 반환해야 하지만 제가간단한 HTML 돔 파서가 모든 td 값을 반환합니까?
<?php
include('classes/simple_html_dom.php');
$html = str_get_html('<table class="pages_navigator">
<tr>
<th style="width:50px;">ID </th>
<th>Business </th>
<th style="width:70px;">Category</th>
<th style="width:50px;">Phone </th>
<th style="width:70px;">State</th>
<th style="width:70px;">City</th>
<tr class="users_tr">
<td>3571</td>
<td>Premium GD</td>
<td>2063199876</td>
<td>Washington</td>
<td>Seattle</td>
<td>3703</td>
</tr>
</table>');
$result = array();
foreach($html->find('tr.users_tr') as $e){
$result[] = $e->plaintext . '<br>';
}
print_r($result);
?>
시도 후
<?php
include('classes/simple_html_dom.php');
$html = str_get_html('<table class="pages_navigator">
<tr>
<th style="width:50px;">ID </th>
<th>Business </th>
<th style="width:70px;">Category</th>
<th style="width:50px;">Phone </th>
<th style="width:70px;">State</th>
<th style="width:70px;">City</th>
<tr class="users_tr">
<td>3571</td>
<td>Premium GD</td>
<td>2063199876</td>
<td>Washington</td>
<td>Seattle</td>
<td>3703</td>
</tr>
</table>');
$tds = $html->find('table.pages_navigator')->find('td') ;
print_r($tds);
?>
태아 오류를 범 마지막 하나는 훌륭하게 작동했지만 모든 TD를 가져옵니다. 단일 문자열로 배열 요소로 각 TD를 가져 오지 않았습니까? 위해서 var_dump 결과
Array (
[0] => 3571 Premium GD 2063199876 Washington Seattle 3703
)
$ 결과를 인쇄하십시오. –
@VaheShadunts는 –
을 추가 할 수 있습니까 var_dump ($ e)? –