Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Facebook stream API错误在浏览器中有效,但在服务器端无效_Python_Facebook_Scraper - Fatal编程技术网

Python Facebook stream API错误在浏览器中有效,但在服务器端无效

Python Facebook stream API错误在浏览器中有效,但在服务器端无效,python,facebook,scraper,Python,Facebook,Scraper,如果我在浏览器中输入此URL,它将返回我感兴趣的有效XML数据 http://www.facebook.com/ajax/stream/profile.php?__a=1&profile_id=36343869811&filter=2&max_time=0&try_scroll_load=false&_log_clicktype=Filter%20Stories%20or%20Pagination&ajax_log=0 但是,如果我从服务器端执行

如果我在浏览器中输入此URL,它将返回我感兴趣的有效XML数据

http://www.facebook.com/ajax/stream/profile.php?__a=1&profile_id=36343869811&filter=2&max_time=0&try_scroll_load=false&_log_clicktype=Filter%20Stories%20or%20Pagination&ajax_log=0
但是,如果我从服务器端执行此操作,它就不会像以前那样工作。现在它只返回这个错误,这似乎是默认的错误消息

{u'silentError': 0, u'errorDescription': u"Something went wrong. We're working on getting it fixed as soon as we can.", u'errorSummary': u'Oops', u'errorIsWarning': False, u'error': 1357010, u'payload': None}
下面是有问题的代码,我尝试了多个用户代理,但都没有用:

import urllib2
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 6.1; he; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3'
uaheader = { 'User-Agent' : user_agent }
wallurl='http://www.facebook.com/ajax/stream/profile.php?__a=1&profile_id=36343869811&filter=2&max_time=0&try_scroll_load=false&_log_clicktype=Filter%20Stories%20or%20Pagination&ajax_log=0'

req = urllib2.Request(wallurl, headers=uaheader)
resp  = urllib2.urlopen(req)        
pageData=convertTextToUnicode(resp.read())
print pageData #and get that error

除了用户代理和IP地址之外,服务器调用和我自己的浏览器有什么区别?

我在chrome和firefox中都尝试了上面的url。它在chrome上工作,但在firefox上失败。在chrome上,我登录了facebook,而在Firefox上,我没有

这可能是造成这种差异的原因。您需要在发布的基于urllib2的脚本中提供身份验证


urllib2的身份验证存在漏洞。

如果您试图从Facebook(或任何第三方服务)获取数据,您应该使用他们的API,而不是抓取页面。