【问题标题】:Facebook stream API error works in Browser but not Server-sideFacebook 流 API 错误适用于浏览器,但不适用于服务器端
【发布时间】:2011-04-05 20:54:02
【问题描述】:

如果我在浏览器中输入此 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 地址之外,服务器调用和我自己的浏览器之间有什么区别?

【问题讨论】:

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

标签: python facebook scraper


【解决方案1】:

我在 chrome 和 firefox 中都尝试了上述网址。它适用于chrome,但在firefox上失败。在 chrome 上,我在 Firefox 上登录了 Facebook,但我没有。

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

在使用 urllib2 进行身份验证时有一个 existing question

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-22
    • 2017-05-16
    • 1970-01-01
    • 2011-05-26
    • 2011-09-28
    • 1970-01-01
    • 2021-10-12
    • 2014-09-17
    相关资源
    最近更新 更多