2011-05-29 61 views
0

夥計們,從RSS中提取的錨文本

我累了我所有的PHP技能來提取一個RSS訂閱域名字符串,並把每個域名作爲一個數組元素,但一切都是徒勞:

這裏是RSS:http://bulliesatwork.co.uk/master/dev/domp/expdom/domains.php

你是否看到一個域名列表,它們是錨定的?我需要的只是提取這些域名,如「abc.co uk」(在.co和.uk之間有一個空格),可以用str_replace刪除 )。

這是我第一次嘗試(使用SimpleHTMLDomParser)

require_once('simple_html_dom.php'); 

$html = file_get_html('http://bulliesatwork.co.uk/master/dev/domp/expdom/domains.php'); 

$domains = $html->find('div[class="entry"] a', 0); 

foreach($domains as $dom) 
{   
    echo str_replace(' ', '.', $dom->plaintext); 
} 

$html->clear(); 
unset($html); 

這是我的另一次嘗試與DOM文檔:

$scrapeurl = 'http://bulliesatwork.co.uk/master/dev/domp/expdom/domains.php';   

$keywords = file_get_contents($scrapeurl); 

$keywords = json_decode($keywords); 

foreach($keywords->responseData->results as $keyword) 
{  
    echo str_replace("...",".",$keyword->title).'<br/>'; 
} 

在這兩種情況下,DOM文檔創建,但它似乎文檔除了我想要提取的域名外,還有所有信息。

請幫我解壓縮域名。

乾杯。

+0

對於rss你不需要簡單的html dom,simplexml_load ...()會做很好的工作 – Ibu 2011-05-29 06:17:31

回答

1

試試這個:

$xmlobj=simplexml_load_string(file_get_contents("http://bulliesatwork.co.uk/master/dev/domp/expdom/domains.php")); 

$res = $xmlobj->xpath("/rss/channel/item/title"); 
$names = array(); 
while(list(, $node) = each($res)) { 
    $names[] = (string)$node; 
} 

$names擁有所有你想要的名字:你需要做字符串替換自己。

+0

謝謝Femi :-) – 2011-05-29 07:10:34