여기 내 HTML 파일에 날짜와 <span>
태그의 링크가 포함되어 있습니다. 누구나 특정 날짜의 링크를 찾을 수 있도록 도와 줄 수 있습니까? 특정 날짜의보기 링크 나 특정 날짜에 대한 링크를 검색 할html dom 파서가 스팬 sibiling에서 href를 추출합니다.
<table>
<tbody>
<tr class="c0">
<td class="c11">
<td class="c8">
<ul class="c2 lst-kix_h6z8amo254ry-0 start">
<li class="c1">
<span>1st Apr 2014 - </span>
<span class="c6"><a class="c4" href="/link.html">View</a>
</span>
</li>
</ul>
</td>
</tr>
</td>
</table>
내 코드는 '본
include('simple_html_dom.php');
$html = file_get_html('link.html');
//store the links in array
foreach($html->find('span') as $value)
{
//echo $value->plaintext . '<br />';
$date = $value->plaintext;
if (strpos($date,$compare_text)) {
//$linkeachday = $value->find('span[class=c1]')->href;
//$day_url[] = $value->href;
//$day_url = Array("text" => $value->plaintext);
$day_url = Array("text" => $date, "link" =>$linkeachday);
//echo $value->next_sibling (a);
}
}
또는
$spans = $html->find('table',0)->find('li')->find('span');
echo $spans;
$num = null;
foreach($spans as $span){
if($span->plaintext == $compare_text){
$next_span = $span->next_sibling();
$num = $next_span->plaintext;
echo($num);
break;
}
}
echo($num);
당신이있는 DOMDocument 클래스를 시도해 봤어 : 경기를 테스트 할 수는 preg_match? –
와우, * simplehtmldom *은 2008 년 이후로 출시되지 않았습니다. 전염병처럼 피해야합니다. 자세한 내용은이 답변의 주석을 참조하십시오. http://stackoverflow.com/a/3577662/283366 – Phil
@phil - 어디에서 볼 수 있습니까? 마지막 업데이트는 2012 년 12 월 – pguardiario