2010-12-08 46 views
0

我使用這個PHP:PHP捲曲搶特定HTML

<?php 

$curl_handle=curl_init(); 
curl_setopt($curl_handle,CURLOPT_URL,'http://www.notrly.com/jackbauer/'); 
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2); 
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); 
$buffer = curl_exec($curl_handle); 
curl_close($curl_handle); 

if (empty($buffer)) 
{ 
    print "Not today"; 
} 
else 
{ 
    print $buffer; 
} 
?> 

沒有在,我要提取和顯示源類「事實」的p標籤!我該怎麼做?如果我使用它來從他們的網站抓取其他人的HTML,那麼它是否違反版權?

回答

2

如果你想使用捲曲,然後下載頁面,並使用DOM解析器,如:

http://simplehtmldom.sourceforge.net/

或者你可以做這樣的事情:

include_once('simple_html_dom.php'); 

$dom = file_get_html('http://www.notrly.com/jackbauer/'); 

foreach($dom->find("div.head div.fact p.fact") as $element) 
    die($element->innertext); 
+0

優秀的,再次,是對某種版權> – benhowdle89 2010-12-08 22:32:00

+0

從我所看到的,沒有版權可見的頁面上。所以我認爲它是公開的。 – 2010-12-08 22:34:54

0

乘坐請看strpos查看字符串...

if (strpos($buffer, '<p class="fact">') !== FALSE) { 
    print "Yay"; 
} 
0

我會檢查在這個question的答案中提到的HTML解析器。至於版權問題,我認爲這將取決於許多因素,包括:

  • 你在與內容做
  • 多少內容您使用的是
  • 什麼是網站你的著作權 正在刮