使用get content后如何过滤数据
我想知道如何在远程网站上查找号码并将其设为变量。
例如,如果我想查找“AMZN”的股票报价,我会使用curl或获取页面“http://stock-quotes.com/AMZN”上的内容,使其成为一个名为$contents的变量字符串
。我有 $contents,我如何找到 AMZN 报价?我正在考虑使用正则表达式来缩小范围,例如找到“AMZN = 35点”,然后执行另一个函数来删除字符串开头和结尾处的“AMZN =”和“点”,以便“只剩下35英寸了。
人们就是这样做的吗?
I want to know how to find a number on a remote website and make it a variable.
For example, if I want to find the stock quote for "AMZN", I would use curl or get contents on the page "http://stock-quotes.com/AMZN" to make it a variable string called $contents
Now that I have $contents, how would I find that AMZN quote? I was thinking of using a regular expression to narrow down the line, like finding "AMZN=35 points", and then perform another function to delete the "AMZN=" and " points" at the start and end of the string so that "35" is all that's left.
Is that how people do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1.) DOM 元素
2.) 简单 XML
3.) preg_match
4.) strpos
1.) DOM Element
2.) Simple XML
3.) preg_match
4.) strpos
我一直所做的(例如在蜘蛛抓取等中)是使用 PHP 中的 simple_html_dom 库,然后检查站点的标记。
如前所述,缺点是如果标记发生变化,您将需要修改代码,但通常这相当容易,并且如果您使用具有信息标记的源(您需要的元素上的一致类名等) .),那么就更容易了。
库链接:http://simplehtmldom.sourceforge.net/
What I've always done (say in spidering, etc.) is to use the simple_html_dom library in PHP, then inspect the markup for the site.
The downside, as mentioned before, is that if the markup changes, you'll need to modify your code, but usually it's fairly easy, and if you use a source that has informative markup (consistent class names on the elements you need, etc.), then it's even easier.
Library link: http://simplehtmldom.sourceforge.net/