0

I have an issue with Python code for parsing prices in Steam and outputting them into Excel. The problem is that I did some mistake in indexing or smth because after I make a bust in Excel I've only seen the first page with items that have been moved 10 times. And I need to grab the Russian names of items and prices in rubles. I tried adding l=russian&cc=ru but it is not worked. Can you please watch my code and maybe you can find a mistakes

from multiprocessing import Pool
from openpyxl import Workbook
from openpyxl.utils import get_column_letter
import requests
from bs4 import BeautifulSoup


def parse_page(page_num, url):
    page_url = url.format(page=page_num)
    response = requests.get(page_url)
    soup = BeautifulSoup(response.text, 'html.parser')
    results = []

    for i in range(1, 11):
        element = soup.select_one(f'#result_{i}_name')
        price = soup.select_one(
            f'#result_{i} > div.market_listing_price_listings_block > div.market_listing_right_cell.market_listing_their_price > span.market_table_value.normal_price > span.normal_price')

        if price:
            text_title = price.text
            results.append(((page_num - 1) * 10 + i + 1, 3, text_title))
        else:
            results.append(((page_num - 1) * 10 + i + 1, 3, f"Элемент не найден на странице {page_num}"))

        if element:
            text_title = element.text
            results.append(((page_num - 1) * 10 + i + 1, 1, (page_num - 1) * 10 + i))
            results.append(((page_num - 1) * 10 + i + 1, 2, text_title))
        else:
            results.append(((page_num - 1) * 10 + i + 1, 1, f"Элемент не найден на странице {page_num}"))

    return results


def parse(url):
    workbook = Workbook()
    sheet = workbook.active
    sheet.cell(row=1, column=1, value="№")
    sheet.cell(row=1, column=2, value="Название предмета")
    sheet.cell(row=1, column=3, value="Цена на ТМ")

    with Pool() as pool:
        page_nums = range(1, 11)
        results = pool.starmap(parse_page, [(page_num, url) for page_num in page_nums])

        for result in results:
            for row, column, value in result:
                sheet.cell(row=row, column=column, value=value)

    sheet.column_dimensions[get_column_letter(1)].width = 5
    sheet.column_dimensions[get_column_letter(2)].width = 80
    sheet.column_dimensions[get_column_letter(3)].width = 30
    sheet.column_dimensions[get_column_letter(4)].width = 30

    workbook.save("results.xlsx")
    print("Результаты сохранены в файл results.xlsx")


def main():
    url = "https://steamcommunity.com/market/search?appid=730#p{page}_popular_desc&l=russian&cc=ru"
    
    parse(url)


if __name__ == '__main__':
    main()

I tried to resolve the problem using ChatGPT but it did not give me the result

Zero
  • 1,807
  • 1
  • 6
  • 17
  • You can emulate changing the language using Selenium but there's no point because even when the language is set to Russian, the prices are still in USD – DarkKnight Jun 27 '23 at 06:55
  • @DarkKnight Yeah this is possible but it will be useless, because translation will be inaccurate, and i planned to compare data from another site where I already received data that i need on original names in Russian – Crashermage Jun 27 '23 at 08:58
  • Have you read through this [post](https://stackoverflow.com/questions/22616644/steam-market-currency-and-xml-format)? – moken Jul 05 '23 at 04:46

0 Answers0