【发布时间】:2015-02-28 19:41:47
【问题描述】:
我正在尝试使用 simple-html-dom 从任何给定的 URL 获取价格。 我使用的运行良好的示例代码来自这里: http://www.sanwebe.com/2013/06/extract-url-content-like-facebook-with-php-and-jquery
//Include PHP HTML DOM parser (requires PHP 5 +)
include_once("Includes/simple_html_dom.inc.php");
//get URL content
$get_content = file_get_html($get_url);
获取标题工作正常:
//Get Page Title
foreach($get_content->find('title') as $element)
{
$page_title = $element->plaintext;
}
但是,当尝试读取 span 元素以获取价格寻找货币符号时,我什么也得不到。
//Get Price
foreach($get_content->find('span') as $element)
{
$price = $element->plaintext;
if (strpos($price, '$') !== FALSE)
{
$page_price = $price;
}
else { $page_price = '0.00';}
}
【问题讨论】:
-
你的获取网址是什么?
-
来自任何给定的网址?为此,您需要一个正则表达式。
-
是的,任何给定的 URL,如果我只是在搜索 $/£ 符号,我需要正则表达式吗?
-
不,你没有。正如您已经注意到的那样, strpos() 就足够了 ^^
-
似乎对我不起作用,哈哈,就像你的测试链接一样。让我再修补一些
标签: php dom file-get-contents simple-html-dom