siddharth ranjan
siddharth ranjan

Reputation: 113

Price history extraction from steam market

I am using following URL to extract the JSON file for the price history
https://steamcommunity.com/market/pricehistory/?appid=730&market_hash_name=P90%20|%20Blind%20Spot%20(Field-Tested)

The python code I am using:

    item = requests.get(URL, cookies={'steamLogin': steamid}); # get item data
    print(str(currRun),' out of ',str(len(allItemNames))+' code: '+str(item.status_code))
    item = item.content
    item = json.loads(item)

Now I went to almost all the solutions that was posted in this community but I am still getting status code as 400 and Items as [].

When I copy paste the URL and open it in browser I am able to see the JSON file with required data but somehow the Jupyter notebook is unable to detect the content

I also tried Beautiful soup to read the content with the following code:

     r = requests.get(url)
     #below code extracts the whole HTML Code of above URL 
     soup = BeautifulSoup(r.content, 'html5lib')
     table = soup.find_all('pre')
     print(table)

Output: []

Upvotes: 0

Views: 1618

Answers (1)

sudden_appearance
sudden_appearance

Reputation: 2195

So you are getting [] because you are not authorized, so you recieve empty json array. You can check it by opening link in incognito (Ctrl+Shift+N) mode.

To authorize you need to set Cookie header to your request, so your code will be as this:

import requests

url = "https://steamcommunity.com/market/pricehistory/?appid=730&market_hash_name=P90%20%7C%20Blind%20Spot%20(Field-Tested)"

headers = {
    "Cookie": "Your cookie"
}

json = requests.get(url, headers=headers).text
...

How to find Cookie (Chrome)

  1. Go to link with json

  2. Press F12 to open Chrome Development Toolkit.

  3. Open Network tab

  4. Reload page.

  5. Double click on first sent request

  6. Open Headers subtab

  7. Scroll to Request Headers

  8. Find Cookie header

Upvotes: 3

Related Questions