如何解析此xml页面 http://evercore:david10@feeds.outgard.net/www.sportsbook.com/trends/203.xml使用PHP simplexml?我收到一条错误消息,说无法加载。
谢谢, 小号
答案 0 :(得分:2)
您需要欺骗代理以使其接受请求。
使用此PHP代码获取结果:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://feeds.outgard.net/www.sportsbook.com/trends/203.xml');
curl_setopt($ch, CURLOPT_GET, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, 'evercore:david10');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
$data = curl_exec($ch);
echo $data;
// Process data with simple XML
curl_close($ch);
答案 1 :(得分:1)
直到@vassilis指出应用了用户代理嗅探,并将其视为达到同一目标的另一种方式,点数转到@vassilis。
<?php
$username = 'evercore';
$password = 'david10';
$opts = array(
'http' => array(
'method' => 'GET',
'header' => sprintf("Authorization: Basic %s\r\nUser-Agent: Foobar!", base64_encode($username.':'.$password))
)
);
$context = stream_context_create($opts);
libxml_set_streams_context($context);
$xml = new SimpleXMLElement(
"http://feeds.outgard.net/www.sportsbook.com/trends/203.xml",
null,
true);
var_dump($xml);