php dom scraping - 抓取产品价格的最佳方法
我正在使用 simpleHtmlDom 进行一些基本的屏幕抓取。不过,我在获取产品价格方面遇到了一些问题。有时我可以让它工作,有时却不能。另外,有时我会得到多个价格...例如,网站上有类似“通常为 100 美元...现在为 79.99 美元”的内容,有什么建议吗?目前,我正在使用这个:
$prices = array();
$prices[] = $html->find("[class*=price]", 0)->innertext;
$prices[] = $html->find("[class*=msrp]", 0)->innertext;
$prices[] = $html->find("[id*=price]", 0)->innertext;
$prices[] = $html->find("[id*=msrp]", 0)->innertext;
$prices[] = $html->find("[name*=price]", 0)->innertext;
$prices[] = $html->find("[name*=msrp]", 0)->innertext;
维多利亚的秘密(Victoria Secret)是我不知道如何获取价格的一个网站......价格看起来只是在随机 HTML 中浮动。
I'm using simpleHtmlDom to do some basic screen scraping. I'm having some problems with grabbing product prices though. Sometimes I can get it to work, sometimes I can't. Also, sometimes I'm getting multiple prices... say for example the website has something like "normally $100... now $79.99" Any suggestions out there? Currently, I'm using this:
$prices = array();
$prices[] = $html->find("[class*=price]", 0)->innertext;
$prices[] = $html->find("[class*=msrp]", 0)->innertext;
$prices[] = $html->find("[id*=price]", 0)->innertext;
$prices[] = $html->find("[id*=msrp]", 0)->innertext;
$prices[] = $html->find("[name*=price]", 0)->innertext;
$prices[] = $html->find("[name*=msrp]", 0)->innertext;
One website that I have no idea of how to grab the price from is Victoria Secret.... the price looks like it's just floating around in random HTML.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,不要使用 simplehtmldom。使用内置的 dom 函数或基于它们的库。如果您想从页面中提取所有价格,您可以尝试如下操作:
First of all, don't use simplehtmldom. Use the built in dom functions or a library that's based on them. If you want to extract all prices from a page you could try something like this: