Capybara / Poltergeist - 资源请求错误:QNetworkReply :: NetworkError

时间:2017-03-30 08:50:35

标签: ruby-on-rails phantomjs capybara poltergeist qnetworkreply

我正在尝试访问 Instagram地址页面

https://www.instagram.com/explore/locations/213385402/london-united-kingdom/

虽然Capybara在其他网页(如个人帖子或个人资料)上取得了成功,但在任何位置页面上,我得到ContentOperationNotPermittedError

我尝试过调试,但我已经用尽所有选择了。

我错过了什么?

编辑:这在开发上运行正常,在Heroku上运行它会带来这个问题。

irb(main):004:0> b.visit 'https://www.instagram.com/explore/locations/213385402/london-united-kingdom/'
2017-03-30T08:45:17 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function () {\n      return typeof __poltergeist;\n    })(); })()"
2017-03-30T08:45:17 [DEBUG] WebPage - evaluateJavaScript result QVariant(QString, "object")
2017-03-30T08:45:17 [DEBUG] WebPage - evaluateJavaScript "(function() { return (function() { var page_id = arguments[0]; var args = []; for(var i=1; i < arguments.length; i++){ if ((typeof(arguments[i]) == 'object') && (typeof(arguments[i]['ELEMENT']) == 'object')){ args.push(window.__poltergeist.get(arguments[i]['ELEMENT']['id']).element); } else { args.push(arguments[i]) } } var _result = (function (name, args) {\n      return __poltergeist.externalCall(name, args);\n    }).apply(this, args); return window.__poltergeist.wrapResults(_result, page_id); })(2,\"currentUrl\",[]); })()"
2017-03-30T08:45:17 [DEBUG] WebPage - evaluateJavaScript result QVariant(QVariantMap, QMap(("value", QVariant(QString, "https://www.instagram.com/p/BSQR9Aggzm3/"))))
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "mid=WNzFfwAEAAHnUL139bDA-GgqTnzo; expires=Wed, 25-Mar-2037 08:44:47 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "s_network=\"\"; expires=Thu, 30-Mar-2017 09:44:57 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "ig_vw=1024; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "fr=0FPrmAjBunUIn2CMi..BY3MWK...1.0.BY3MWK.; HttpOnly; expires=Wed, 28-Jun-2017 08:44:58 GMT; domain=.facebook.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "rur=PRN; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "csrftoken=yymkEesbNZEzwrlL42HJeyNmFIghmOf1; secure; expires=Thu, 29-Mar-2018 08:44:59 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "ig_pr=1; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "mid=WNzFfwAEAAHnUL139bDA-GgqTnzo; expires=Wed, 25-Mar-2037 08:44:47 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "s_network=\"\"; expires=Thu, 30-Mar-2017 09:44:57 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "fr=0FPrmAjBunUIn2CMi..BY3MWK...1.0.BY3MWK.; HttpOnly; expires=Wed, 28-Jun-2017 08:44:58 GMT; domain=.facebook.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "rur=PRN; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "csrftoken=yymkEesbNZEzwrlL42HJeyNmFIghmOf1; secure; expires=Thu, 29-Mar-2018 08:44:59 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "ig_pr=1; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "ig_vw=1024; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] WebPage - updateLoadingProgress: 10
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "mid=WNzFfwAEAAHnUL139bDA-GgqTnzo; expires=Wed, 25-Mar-2037 08:44:47 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "s_network=\"\"; expires=Thu, 30-Mar-2017 09:44:57 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "fr=0FPrmAjBunUIn2CMi..BY3MWK...1.0.BY3MWK.; HttpOnly; expires=Wed, 28-Jun-2017 08:44:58 GMT; domain=.facebook.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "csrftoken=yymkEesbNZEzwrlL42HJeyNmFIghmOf1; secure; expires=Thu, 29-Mar-2018 08:44:59 GMT; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "ig_pr=1; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "ig_vw=1024; domain=www.instagram.com; path=/"
2017-03-30T08:45:17 [DEBUG] CookieJar - Saved "rur=PRN; domain=www.instagram.com; path=/"
==> 2017-03-30T08:45:17 [DEBUG] Network - Resource request error: QNetworkReply::NetworkError(ContentOperationNotPermittedError) ( "Error downloading https://www.instagram.com/explore/locations/213385402/london-united-kingdom/ - server replied: Forbidden" ) URL: "https://www.instagram.com/explore/locations/213385402/london-united-kingdom/"
2017-03-30T08:45:17 [DEBUG] WebPage - updateLoadingProgress: 100
2017-03-30T08:45:17 [DEBUG] WebPage - setupFrame ""
=> {"status"=>"fail"}

这就是我的水豚/恶作剧者:

def setup_session
  driver_options = { js_errors: false,
                    logger: NilLogger.new,
                    phantomjs_logger: STDOUT,
                    phantomjs: Phantomjs.path,
                    phantomjs_options: [
                      '--debug=true',
                      '--ignore-ssl-errors=true',
                      '--ssl-protocol=ANY',
                      '--web-security=false',
                      '--local-to-remote-url-access=true'
                    ],
                    debug: false  }


  Capybara.configure do |config|
    config.register_driver :poltergeist do |app|
      driver = Capybara::Poltergeist::Driver.new(app, driver_options)
      driver.headers = { 'User-Agent' => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36" }
      driver
    end

    config.run_server = false
    config.app_host = 'https://appname.herokuapp.com/'
    config.default_driver = :poltergeist
    config.default_max_wait_time = 60
  end

  Capybara.current_session
end

1 个答案:

答案 0 :(得分:0)

显然Instagram禁止了Heroku。您应该使用代理从Heroku转到Instagram。如何配置Capybara使用代理在此问题中回答 - Using poltergeist with a proxy? 您可以在任何代理列表中找到的代理 - https://free-proxy-list.net/