<small id='xlwIw'></small><noframes id='xlwIw'>

      <legend id='xlwIw'><style id='xlwIw'><dir id='xlwIw'><q id='xlwIw'></q></dir></style></legend>
      <tfoot id='xlwIw'></tfoot>
    1. <i id='xlwIw'><tr id='xlwIw'><dt id='xlwIw'><q id='xlwIw'><span id='xlwIw'><b id='xlwIw'><form id='xlwIw'><ins id='xlwIw'></ins><ul id='xlwIw'></ul><sub id='xlwIw'></sub></form><legend id='xlwIw'></legend><bdo id='xlwIw'><pre id='xlwIw'><center id='xlwIw'></center></pre></bdo></b><th id='xlwIw'></th></span></q></dt></tr></i><div id='xlwIw'><tfoot id='xlwIw'></tfoot><dl id='xlwIw'><fieldset id='xlwIw'></fieldset></dl></div>
        • <bdo id='xlwIw'></bdo><ul id='xlwIw'></ul>

        XHR 请求 URL 在尝试解析其内容时说不存在

        XHR request URL says does not exist when attempting to parse it#39;s content(XHR 请求 URL 在尝试解析其内容时说不存在)

        <i id='GYOvv'><tr id='GYOvv'><dt id='GYOvv'><q id='GYOvv'><span id='GYOvv'><b id='GYOvv'><form id='GYOvv'><ins id='GYOvv'></ins><ul id='GYOvv'></ul><sub id='GYOvv'></sub></form><legend id='GYOvv'></legend><bdo id='GYOvv'><pre id='GYOvv'><center id='GYOvv'></center></pre></bdo></b><th id='GYOvv'></th></span></q></dt></tr></i><div id='GYOvv'><tfoot id='GYOvv'></tfoot><dl id='GYOvv'><fieldset id='GYOvv'></fieldset></dl></div>

        <small id='GYOvv'></small><noframes id='GYOvv'>

            <tbody id='GYOvv'></tbody>
          • <bdo id='GYOvv'></bdo><ul id='GYOvv'></ul>
              <legend id='GYOvv'><style id='GYOvv'><dir id='GYOvv'><q id='GYOvv'></q></dir></style></legend>
                1. <tfoot id='GYOvv'></tfoot>
                  本文介绍了XHR 请求 URL 在尝试解析其内容时说不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我使用 Scrapy 为我的问题构建一个完整的解决方案之前,我发布了一个我想要做的简单版本:

                  Before I build a full solution to my problem using Scrapy I am posting a simplistic version of what I want to do:

                  import requests
                  
                  url = 'http://www.whoscored.com/stageplayerstatfeed/?field=1&isAscending=false&orderBy=Rating&playerId=-1&stageId=9155&teamId=32"'
                  
                  params = {'d': date.strftime('%Y%m'), 'isAggregate': 'false'}
                  headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36'}
                  
                  response = requests.get(url, params=params, headers=headers)
                  
                  fixtures = response.body
                  #fixtures = literal_eval(response.content)
                  print fixtures 
                  

                  此代码表示上述 URL 不存在.该 URL 与您从本页主表的总体"切换到主页"选项卡时提交的 XHR 请求相关:

                  This code is saying that the above URL does not exist. The URL relates to an XHR request that is submitted when you toggle from the 'Overall' to the 'Home' tab of the main table on this page:

                  http://www.whoscored.com/Teams/32/
                  

                  如果您在 Google Developer Tools 的控制台中激活 XHR 日志记录,您可以看到 XHR 请求和从服务器以字典形式发送的响应(这是预期的格式).

                  If you activate XHR logging within the Console of Google Developer Tools you can see both the XHR request and the response sent from the server in the form of a dictionary (which is the expected format).

                  谁能告诉我为什么上面的代码没有返回我希望看到的数据?

                  Can anyone tell me why the above code is not returning the data I would expect to see?

                  谢谢

                  推荐答案

                  你有几个问题:

                  • 网址应为 http://www.whoscored.com/stageplayerstatfeed
                  • 错误的GET参数
                  • 缺少重要的必填标题
                  • 你需要 response.json(),而不是 response.body
                  • the url should be http://www.whoscored.com/stageplayerstatfeed
                  • wrong GET parameters
                  • missing important required headers
                  • you need response.json(), not response.body

                  固定版本:

                  import requests
                  
                  url = 'http://www.whoscored.com/stageplayerstatfeed'
                  params = {
                      'field': '1',
                      'isAscending': 'false',
                      'orderBy': 'Rating',
                      'playerId': '-1',
                      'stageId': '9155',
                      'teamId': '32'
                  }
                  headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36',
                             'X-Requested-With': 'XMLHttpRequest',
                             'Host': 'www.whoscored.com',
                             'Referer': 'http://www.whoscored.com/Teams/32/'}
                  
                  response = requests.get(url, params=params, headers=headers)
                  
                  fixtures = response.json()
                  print fixtures
                  

                  打印:

                  [
                      {
                          u'AccurateCrosses': 0,
                          u'AccurateLongBalls': 10,
                          u'AccuratePasses': 89,
                          u'AccurateThroughBalls': 0,
                          u'AerialLost': 2,
                          u'AerialWon': 4,
                          ...
                      },
                      ...
                  ]
                  

                  这篇关于XHR 请求 URL 在尝试解析其内容时说不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)
                    <tbody id='bhA10'></tbody>

                  <small id='bhA10'></small><noframes id='bhA10'>

                    <tfoot id='bhA10'></tfoot>
                      <bdo id='bhA10'></bdo><ul id='bhA10'></ul>
                      <legend id='bhA10'><style id='bhA10'><dir id='bhA10'><q id='bhA10'></q></dir></style></legend>

                          1. <i id='bhA10'><tr id='bhA10'><dt id='bhA10'><q id='bhA10'><span id='bhA10'><b id='bhA10'><form id='bhA10'><ins id='bhA10'></ins><ul id='bhA10'></ul><sub id='bhA10'></sub></form><legend id='bhA10'></legend><bdo id='bhA10'><pre id='bhA10'><center id='bhA10'></center></pre></bdo></b><th id='bhA10'></th></span></q></dt></tr></i><div id='bhA10'><tfoot id='bhA10'></tfoot><dl id='bhA10'><fieldset id='bhA10'></fieldset></dl></div>