PHP-curl 还是 simplexml_load_file?
我正在尝试解析来自 fonefinder.net 的信息。我试图使用 simplexmlload_file,但无法成功加载页面。
现在,我正在研究 Curl。但我也不确定这是否有效。
我基本上只是想从 fonefinder 页面获取 html,并解析它以获取电话运营商和城市。
这可能吗?怎么办?
I'm trying to parse information from fonefinder.net. I was trying to use simplexmlload_file, but couldn't get the page to load successfully.
Now, I'm looking into Curl. But I'm not sure if this will work either.
I basically just want to take the html from the fonefinder page, and parse it to get phone carrier and city.
Is that possible? How?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SimpleXML 仅在 HTML 格式正确的情况下才有效 - 但这种情况很少发生;)
您可以执行简单的 cURL 调用来获取数据,最简单的事情可能是使用正则表达式来获取您需要的信息。
然而,解决方案并不容易提供给您,没有任何进展。但这只是一个想法。
SimpleXML will only work if the HTML is formatted correctly - and that is rarely the case ;)
You could do a simple cURL call to fetch the data and the easiest thing would probably be using a regular expression to get the information you need.
The solution however is not easy to supply you with, with nothing to go on. But this was an idea.
我建议使用:
http://www.de。 php.net/manual/en/function.file-get-contents.php 获取文档
http://www.php.net/manual/en/domdocument.loadhtml.php 加载它
http://www.php.net/manual/en/class.domxpath.php 从中获取信息
或者使用此处的搜索功能,这个问题一定被问了一遍又一遍,例如 PHP :使用xpath()从html页面获取内容
I Recommend using:
http://www.de.php.net/manual/en/function.file-get-contents.php to get the document
http://www.php.net/manual/en/domdocument.loadhtml.php to load it
http://www.php.net/manual/en/class.domxpath.php to get the information from it
Or use the search function here, that question must have been asked over and over, for example PHP: Fetch content from a html page using xpath()