2012-09-19 33 views
0

我得刮一個網址,並得到一個項目的價格。 我正在嘗試簡單的PHP DOM,但有一些我做錯了。 這是代碼的一部分,其中價格是:用dd標記刮網址php

<div class="Right"> 

        <dl class="Price Offer" itemprop="offers" itemscope itemtype="http://schema.org/Offer"> 
         <dt>Price:</dt> 
         <dd itemprop="price">$49.99</dd> 
         <link itemprop="availability" href="http://schema.org/InStock" content="In Stock"/> 
        </dl> 

        <dl class="Identifier"> 
         <dt>Prod ID:</dt> 
         <dd itemprop="productID">68947</dd> 
        </dl> 
       </div> 

我需要得到$ 49.99,沒有別的,但我真的失去了。 我試過使用 - >明文,然後做一些爆炸或str_replace,但似乎我做錯了什麼。

This is the url i'm trying to scrape

謝謝!

+0

是的,代碼? – dbf

+0

$ html = file_get_html($ url) - > plaintext;從那裏開始,實現了剝離標籤的功能,但它不能在dd和dt標籤上工作..... –

+0

K,請勿將它置於評論中,請將其放入您的帖子中。 – dbf

回答

0

愚蠢的和簡單的解決方案:

<?php 
$scraptedText; //<-- your scraped site 

$scraptedText = split('<dd itemprop="price">',$scraptedText); 
$scraptedText = split('</dd>', $scraptedText[1]); 
$scraptedText = $scraptedText[0]; 

林沒有真正進入正則表達式,但這應該工作。

+0

優秀!!謝謝。效果很好。 –