Пробема с парсингом
При парсинге страницы я не могу по какой-то причине найти тег с определенным классом. Без понятия, почему так происходит. Вот пример кода:
def function1_request(url):
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.152 YaBrowser/21.2.3.100 Yowser/2.5 Safari/537.36'
}
ret_url = requests.get(url, HEADERS)
return ret_url
def sbor_dannyh(dan1_url):
dan_url = function1_request(dan1_url)
soap1 = BS(dan_url.text, 'html.parser')
#print(soap1)
price_thing = soap1.find('span', class_='market_listing_price market_listing_price_with_fee').text.strip()
#print(price_thing)
#print(price_thing.split(' ')[0])
print(price_thing[:-5])
standart_price = soap1.find('span', {'id': 'market_commodity_buyrequests'})
print(standart_price)
print(sbor_dannyh('https://steamcommunity.com/market/listings/730/StatTrak%E2%84%A2%20CZ75-Auto%20%7C%20Imprint%20%28Field-Tested%29?filter=%22Astralis%20Atlanta%202017%2C%20Astralis%20Atlanta%202017%22'))
Я не могу понять, в чем проблема. Помогите пожалуйста!
Ответы (2 шт):
Автор решения: Jack_oS
→ Ссылка
на странице, которая указана в коде, есть цена (начальная цена) и вот ее я не могу спарсить
Попробуйте так:
import requests
from bs4 import BeautifulSoup
headers = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36'}
url = 'https://steamcommunity.com/market/listings/730/StatTrak%E2%84%A2%20CZ75-Auto%20%7C%20Imprint%20%28Field-Tested%29?filter=%22Astralis%20Atlanta%202017%2C%20Astralis%20Atlanta%202017%22'
r = requests.get(url, headers=headers)
soup = BeautifulSoup(r.content, 'html.parser')
# .find_all() на случай, если вернется не одна позиция
market_listing_rows = soup.find_all('div', class_='market_recent_listing_row')
for row in market_listing_rows:
name = row.find('span', class_='market_listing_item_name').text
price_with_fee = row.find('span', class_='market_listing_price_with_fee').text.strip()
price_with_publisher_fee_only = row.find('span', class_='market_listing_price_with_publisher_fee_only').text.strip()
price_without_fee = row.find('span', class_='market_listing_price_without_fee').text.strip()
print(name)
print(price_with_fee)
print(price_with_publisher_fee_only)
print(price_without_fee)
выведет:
StatTrak™ CZ75-Auto | Imprint (Field-Tested)
87,74 pуб.
83,93 pуб.
76,30 pуб.
Автор решения: user440354
→ Ссылка
То что вам надо находится вот тут https://steamcommunity.com/market/itemordershistogram?country=RU&language=russian¤cy=5&item_nameid=165027660&two_factor=0 вытаскиваете со страницы переменную item_nameid=165027660
потом уже запрос на https://steamcommunity.com/market/itemordershistogram, где выводится вся инфа по ордерам
