Python scraping XHR returns ValueError: Too many values to unpack
Question: So for educational purposes I've got this piece of code written to scrape the
'detailed' tab of this webpage :
<https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/England-
Premier-League-2015-2016>

However it gives me a value error : too many values to unpack.

I'm still quite beginner level at Python so I just can't figure it out why
this shows up.

    
    
    import requests
    
    
    url = 'https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/England-Premier-League-2015-2016'
    
    params = {
    'category:shots',
    'subcategory:zones',
    'statsAccumulationType:0',
    'timeOfTheGameStart:0',
    'timeOfTheGameEnd:5',
    'stageId:12496',
    'sortBy: Rating', 
    'page: 1',
    'isCurrent: True'
    }
    
    headers = {
            'User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
            'X-Requested-With: XMLHttpRequest',
            'Host: www.whoscored.com'
            'Referer: https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/England-Premier-League-2015-2016',}
    
    response = requests.get(url, params=params, headers=headers)
    
    stats = response.json()
    print stats
    


Answer: You are incorrectly defining the `params` \- currently it is actually a set of
strings. Break down the strings to produce key-value pairs and create a
dictionary instead:

    
    
    params = {
        'category': 'shots',
        'subcategory': 'zones',
        'statsAccumulationType': '0',
        'timeOfTheGameStart': '0',
        'timeOfTheGameEnd': '5',
        'stageId': '12496',
        'sortBy': 'Rating',
        'page': '1',
        'isCurrent': 'True'
    }
    

Same goes for `headers`:

    
    
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36',
        'X-Requested-With': 'XMLHttpRequest',
        'Host': 'www.whoscored.com',
        'Referer': 'https://www.whoscored.com/Regions/252/Tournaments/2/Seasons/5826/Stages/12496/TeamStatistics/England-Premier-League-2015-2016'
    }
    

This would help to fix the error, but you would not get the JSON response as
is. I suspect the `url` you are using is not the right one, recheck that.

Also, if you want to simulate the request that you observe in Chrome Developer
Tools - do the following:

  * right click on a particular request
  * select "Copy as cURL"
  * go to <http://curl.trillworks.com/> and convert it to Python+Requests code

