1

ここに私が探しているものがあります:

HTML形式でいくつかのデータを表示するリンクがあります:

http://www.118.com/people-search.mvc...0&pageNumber=1

データは以下の形式で提供されます:

<div class="searchResult regular"> 

バード・ジョン

56 Leathwaite Road
London
SW11 6RS 020 7228 5576

PHP ページで上記の URL を実行し、上記のタグに基づいて結果 HTML ページからデータを抽出/解析する必要があります。h2=Name address=Address telephoneNumber= Phone Number として

それらを表形式で表示します。

私はこれを手に入れましたが、HTMLページのTEXT形式のみを示していますが、ある程度機能します:

<?
function get_content($url) 
{ 
$ch = curl_init(); 

curl_setopt ($ch, CURLOPT_URL, $url); 
curl_setopt ($ch, CURLOPT_HEADER, 0); 

ob_start(); 

curl_exec ($ch); 
curl_close ($ch); 
$string = ob_get_contents(); 

ob_end_clean(); 

return $string; 

} 


$content = get_content("http://www.118.com/people-search.mvc?Supplied=true&Name=william&Location=Crabtree&pageSize=50&pageNumber=1"); 
echo $content;
$content = get_content("http://www.118.com/people-search.mvc?Supplied=true&Name=william&Location=Crabtree&pageSize=50&pageNumber=2"); 
echo $content;
$content = get_content("http://www.118.com/people-search.mvc?Supplied=true&Name=william&Location=Crabtree&pageSize=50&pageNumber=3"); 
echo $content;
$content = get_content("http://www.118.com/people-search.mvc?Supplied=true&Name=william&Location=Crabtree&pageSize=50&pageNumber=4"); 
echo $content;

?>
4

1 に答える 1

4

dom パーサーSimple HTMLなどを使用する必要があります

ファイルを dom オブジェクトに読み込み、適切なセレクターを使用して解析します。

$html = new simple_html_dom("http://www.118.com/people-search.mvc...0&pageNumber=1");

foreach($html->find(.searchResult+regular) as $div) {
  //parse div contents here to extract name and address etc.
}
$html->clear();
unset($html);

詳細については、Simple HTMLのドキュメントを参照してください。

于 2010-09-06T08:46:42.460 に答える