2011-01-06 8 views
0

페이지의 특정 <tr> 태그에서 동적 방식으로 텍스트를 가져 오는 방법이 있습니까?특정 <tr> 태그에서 텍스트 가져 오기

값이 "a1"인 <tr>이있는 페이지가 있습니다. 이 <tr> 태그의 텍스트 만 가져 와서 페이지에 표시하고 싶습니다. 이것이 가능한가? 여기

는 HTML입니다 :

<html><tr id='ieconn2' > 
    <td><table width='100%'><tr><td valign='top'><table width='100%'><tr><td><script type="text/javascript"><!-- 
google_ad_client = "pub-4503439170693445"; 
/* 300x250, created 7/21/10 */ 
google_ad_slot = "7608120147"; 
google_ad_width = 300; 
google_ad_height = 250; 
//--> 
</script> 
<script type="text/javascript" 
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> 
</script><br>When Marshall and Lily fear they will never get pregnant, they see a specialist who can hopefully help move the process along. Meanwhile, Robin starts her new job.<br><br><b>Source: </b>CBS 

<br>&nbsp;</td></tr><tr><td><b>There are no foreign summaries for this episode:</b> <a href='/edit/shows/3918/episode_foreign_summary/?eid=1065002553&season=6'>Contribute</a></td></tr><tr><td><b>English Recap Available: </b> <a href='/How_I_Met_Your_Mother/episodes/1065002553?show_recap=1'>View Here</a></td></tr></table></td><td valign='top' width='250'><div align='left'> 
<img alt='How I Met Your Mother season 6 episode 13' src="http://images.tvrage.com/screencaps/20/3918/1065002553.jpg" width="248" border='0' > 
</div><div align='center'><a href='/How_I_Met_Your_Mother/episodes/1065002553?gallery=1'>6 gallery images</a></div></td></tr></table></td></tr><tr> 
    <td background='/_layout_v3/buttons/title.jpg' height='39' width='631' align='center'> 
<table width='100%' cellpadding='0' cellspacing='0' style='margin: 1px 1px 1px 1px;'> 
<tr> 
<td align='left' style='cursor: pointer;' onclick="SwitchHeader('ieconn3','iehide3','26')" width='90'>&nbsp;<span style='font-size: 15px; font-weight: bold; color: black; padding-left: 8px;' id='iehide3'><img src='/_layout_v3/misc/minus.gif' width='26'></span></td> 
<td align='center' style='cursor: pointer;' onclick="SwitchHeader('ieconn3','iehide3','26')" ><h5 class='nospace'>Sponsored Links</h5><a name=''></a></td> 

<td align='left' width='90' >&nbsp;</td></tr></table></td> 
</tr></html> 

내가 얻고 싶은 모든이 텍스트입니다 : "마샬과 릴리가 임신을 결코 두려워 할 때, 그들은 희망에 따라 과정을 이동할 도움을 줄 수있는 전문가를 참조하십시오. 한편, 로빈은 그녀의 새로운 작업을 시작합니다 "

+0

원하는 것을 보여 줄 수 있습니까? – lonesomeday

+0

은 입니다. 값을 가져 오시겠습니까? – Praneeth

+0

@Praneeth PHP에서 jQuery를 사용하는 것은 상당히 어렵습니다. – lonesomeday

답변

3

를?

$dom = new DomDocument; 
libxml_use_internal_errors(true); 
$dom->loadHTMLFile(...); 
libxml_clear_errors(); 

$xpath = new DomXpath($dom); 
$nodes = $xpath->query('/html/body/tr/td/table/tr/td/table/tr/td'); 
foreach ($nodes as $node) 
{ 
    echo $node->nodeValue, "\n"; 
} 
+0

그리고 다시 저장을 위해 ajreal ... :) – t0mgs

2

난 당신이 다음에 당신이 수를 잘 수행 할 작업을 가정하면 :.

$url = “http://url.tld”; 
$str = file_get_contents($url); 

거기에서 불과 PHP의 문자열 방지 동작을 사용에를 당신이 좋아하지 않는 부분을 자르려면 on을 사용하십시오 (아마도 프로세스 속도를 높이기 위해 정규 표현식을 생성 할 것입니다).

위의 방법은이 같은 더 복잡한 기능을 시도 할 수 있습니다 작동하지 않는 경우 :이 방법에 대해

function get_url_contents($url){ 
    $crl = curl_init(); 
    $timeout = 5; 
    curl_setopt ($crl, CURLOPT_URL,$url); 
    curl_setopt ($crl, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt ($crl, CURLOPT_CONNECTTIMEOUT, $timeout); 
    $ret = curl_exec($crl); 
    curl_close($crl); 
    return $ret; 
} 
+0

@ Cadoc-thanks! 문자열에서 정확한 태그를 제거하는 방법에 익숙하지 않습니다. 출력에서 모든 태그를 제거 할 수는 있지만 원하는 부분 만 전체 문서가 아닌 부분 만 제공합니다. – t0mgs

+0

+0 작업에 잘못된 도구가 있습니다. 이것은 OP의 삶이 필요 이상으로 복잡해질 것입니다. – Gordon

+0

@Gordon - 그는 대답을했습니다. 너? – t0mgs