如果您还没有听说过 Woot.com,那么您就一直生活在岩石之下。对于那些一直处于众所周知的岩石之下的人,这里是情节:
- 每天,Woot 销售一种产品。
- 一旦商品售罄,就没有更多商品可供购买。
- 您不知道有多少一件商品有货,您一次只能购买三件。
- 无论产品价格和数量如何,运费均为 5.00 美元。
- 每隔一段时间(通常是一次)一个月),Woot 有一个“Woot-off”,在那里他们出售一件又一件物品,直到所有东西都卖完。
- 更罕见的是“Bag o’ Crap”。你在买什么?一袋垃圾,但“BOC”可能是笔记本电脑包带或大屏幕电视。祝你顺利完成结帐流程——BOC 通常会关闭服务器。
- Woot 从简单的科技产品 (woot.com) 扩展到葡萄酒和 T 恤。
不用说,Woot 是一个有趣的网站。我创建了一个返回产品名称、价格和图像的 PHP 脚本。
代码
//get the page content
$woot_content = file_get_contents('http://shirt.woot.com');
//parse for product name
$name = get_match('/<h3[^>]*>(.*)</h3>/is',$woot_content);
//parse for product price
$price = get_match('/<div ><span id="PriceSpan">(.*)<dl >/is',$woot_content);
//parse for product image
$image = get_match('/<div >(.*?)/>/is',$woot_content).' />';
//parse for product sold out?
$sold_out = substr_count(strtolower($woot_content),'sold out!') ? 'Sold Out!' : 'Product Left!';
$content.= '<h1>Product Name</h1>'.$name.'<br /><br />';
$content.= '<h1>Product Price</h1>'.$price.'<br /><br />';
$content.= '<h1>Product Image</h1>'.$image.'<br /><br />';
$content.= '<h1>Product Sold Out?</h1>'.$sold_out.'<br /><br />';
//gets the match content
function get_match($regex,$content)
{
preg_match($regex,$content,$matches);
return $matches[1];
}
关于代码的几点说明:
- 您可以使用 file_get_contents() 函数或我的 URL 下载内容函数获取内容。您的偏好取决于服务器的安全设置。
- 您可以使用以下 URL,具体取决于您想要的内容/产品:
- http://woot.com
- http://shirt.woot.com
- http://wine.woot.com
