pythonpython-3.xbeautifulsouppython-requestspython-requests-html

Getting the price of the game from EGS


I'm trying to get the price of the game from the epic games store, but I get a 403 error

import requests
from bs4 import BeautifulSoup

url = "https://store.epicgames.com/ru/p/cities-skylines"

response = requests.get(url)

if response.status_code == 200:
    soup = BeautifulSoup(response.text, 'html.parser')

    price_element = soup.find(class_='css-119zqif')

    if price_element is not None:
        price = price_element.get_text(strip=True) 
        print("Price Cities: Skylines:", price)
    else:
        print("Error")
else:
    print("Error:", response.status_code)

I tried to access the game page directly, and take the price information from the class in html, but I get the error "Request error: 403"


Solution

  • You get to the cloudflare page dedicated to fighting robots. To get around this limitation, you need to imitate a real person. To do this, you can use the following library or similar. Here is an example of working code. Don't forget to pip install cloudscraper.

    from bs4 import BeautifulSoup
    import cloudscraper
    
    url = "https://store.epicgames.com/ru/p/cities-skylines"
    
    scraper = cloudscraper.create_scraper()
    response = scraper.get(url)
    
    if response.status_code == 200:
        soup = BeautifulSoup(response.text, 'html.parser')
    
        price_element = soup.find('div', 'css-169q7x3').find(class_='css-119zqif')
        print(price_element)
    
        if price_element is not None:
            price = price_element.get_text(strip=True) 
            print("Price Cities: Skylines:", price)
        else:
            print("Error")
    else:
        print("Error:", response.status_code)
    

    result:

    Price Cities: Skylines: 330 ₽
    

    One remark. This library has free limitations and sometimes an error may occur: cloudscraper.exceptions.CloudflareChallengeError: Detected a Cloudflare version 2 Captcha challenge, This feature is not available in the opensource (free) version. Ignore it and get the result. But you can always rewrite your code using this API. If you sign up, they will give you a token for 10,000 requests per month. If this option does not suit you, look in the direction of selenium.