2012-10-18 24 views
2

我从RSS源拉:使用simplexml_load_file文件是空的

http://search.library.utoronto.ca/UTL/index?Ntt=starcraft&Ntk=Anywhere&Ntx=mode+matchallpartial&N=0&Nu=p_work_normalized&Np=1&rss=1

如果您导航到以浏览器,你会得到一个不错的XML页面。

但是,如果我这样做

simplexml_load_file("the above url"); 
在PHP

,我得到

1: parser error : Document is empty 
1: parser error : Start tag expected, '<' not found in my_file 

那么,为什么可以在浏览器中得到,但不是PHP?

如果我这样做file_get_contents("the above url")函数失败返回FALSE。

回答

1

该网站阻止来自PHP的请求。

首先运行

<?php 
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0'); 

(或其他有效的用户代理),它会工作。

+0

很酷的作品,谢谢 –

+0

太好了。欢迎来到这个网站! – limos

相关问题