2

我试图从 html 源代码中获取价格,这里是源代码的一部分

 <h1>
    <span id="ctl00_PageHeaderContentPlaceHolder_lblRegion">Product Name</span>
    <strong id="ctl00_PageHeaderContentPlaceHolder_divFiyat" class="price">
        749 €
        <small>
            2007 TL
            <small class="nightday">
                <span id="ctl00_PageHeaderContentPlaceHolder_lblNightDay">Un related detals</span></small></small>
    </strong>
</h1>

正如您在此处看到的,它是非常指定的 id。这是我的代码..

 $Tour_Price ="/<span id=\"ctl00_PageHeaderContentPlaceHolder_divFiyat\" class=\"price\">(.*?)<\/span>/i";
        preg_match($Tour_Price , $Tur_Fiyat, $Result_Price);
        echo "<strong>Result:</strong>".$Result_Price[1];

我的代码在源代码的其他部分完美运行。但价格只是没有。请拍摄想法。感谢所有感兴趣的人:)

4

2 回答 2

0

试试这个代码:

$Tour_Price ="/<strong id=\"ctl00_PageHeaderContentPlaceHolder_divFiyat\" class=\"price\">(.*?)<\/strong>/is";
preg_match($Tour_Price , $Tur_Fiyat, $Result_Price);
echo "<strong>Result:</strong>".$Result_Price[1];

注意:更改为spantostrong{...}/ito{...}/is

于 2013-08-23T11:42:11.973 回答
0

您指定<span而不是<strong在正则表达式的开头。

但在你的源跨度和强有不同的ID。

于 2013-08-23T11:38:09.200 回答