Alexa api 站点信息 xml 格式转换为 php 值
我尝试使用亚马逊的 Alexa api。我想接收网站数据。
我创建一个 url 来接收数据,我以 xml 格式获取该数据。
当我尝试读取此文件时,
$xml = simplexml_load_file('test.xml');
print_r($xml);
我只得到代码“SimpleXMLElement Object ()”。
如何从这个 xml 获取数据到 php?
我得到的 xml 文件的一部分;
<?xml version="1.0"?>
<aws:UrlInfoResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11"><aws:OperationRequest><aws:RequestId>removed</aws:RequestId></aws:OperationRequest><aws:UrlInfoResult><aws:Alexa>
<aws:TrafficData>
<aws:DataUrl type="canonical">yahoo.com</aws:DataUrl>
<aws:Rank>4</aws:Rank>
<aws:UsageStatistics>
<aws:UsageStatistic>
<aws:TimeRange>
<aws:Months>3</aws:Months>
</aws:TimeRange>
<aws:Rank>
<aws:Value>4</aws:Value>
<aws:Delta>0</aws:Delta>
</aws:Rank>
<aws:Reach>
<aws:Rank>
<aws:Value>4</aws:Value>
<aws:Delta>0</aws:Delta>
</aws:Rank>
<aws:PerMillion>
<aws:Value>228,260</aws:Value>
<aws:Delta>-2.83%</aws:Delta>
</aws:PerMillion>
</aws:Reach>
<aws:PageViews>
<aws:PerMillion>
<aws:Value>14,390</aws:Value>
<aws:Delta>-10.59%</aws:Delta>
</aws:PerMillion>
<aws:Rank>
I try to make use of the alexa api by amazon. I want to receive website data.
I create a url to receive the data, I get this in a xml format.
When I try to read this file by
$xml = simplexml_load_file('test.xml');
print_r($xml);
I get just the code 'SimpleXMLElement Object ( ) '.
How can I get the data to php from this xml?
A Part of the xml file I get ;
<?xml version="1.0"?>
<aws:UrlInfoResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11"><aws:OperationRequest><aws:RequestId>removed</aws:RequestId></aws:OperationRequest><aws:UrlInfoResult><aws:Alexa>
<aws:TrafficData>
<aws:DataUrl type="canonical">yahoo.com</aws:DataUrl>
<aws:Rank>4</aws:Rank>
<aws:UsageStatistics>
<aws:UsageStatistic>
<aws:TimeRange>
<aws:Months>3</aws:Months>
</aws:TimeRange>
<aws:Rank>
<aws:Value>4</aws:Value>
<aws:Delta>0</aws:Delta>
</aws:Rank>
<aws:Reach>
<aws:Rank>
<aws:Value>4</aws:Value>
<aws:Delta>0</aws:Delta>
</aws:Rank>
<aws:PerMillion>
<aws:Value>228,260</aws:Value>
<aws:Delta>-2.83%</aws:Delta>
</aws:PerMillion>
</aws:Reach>
<aws:PageViews>
<aws:PerMillion>
<aws:Value>14,390</aws:Value>
<aws:Delta>-10.59%</aws:Delta>
</aws:PerMillion>
<aws:Rank>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这或多或少是您所需要的:
注意:
this is more or less what you need:
notes: