Итак, я пытаюсь очистить скины CS: GO, пытаюсь вернуть: имя скина, цену и коллекцию - в таком порядке.
Это один из многих способов, которые я пробовал it.
from bs4 import BeautifulSoup
import requests
import urllib3
urllib3.disable_warnings()
def webscrape():
url = "https://csgostash.com/weapon/AWP"
res = requests.get(url = url)
soup = BeautifulSoup(res.text, "html.parser")
titles = soup.find_all('div', class_="well result-box nomargin")
prices = soup.find_all('div', class_="price")
collection = soup.find_all('div', class_="collection")
for title in titles:
title = title.find('a')
if title:
title = title.text
for price in prices:
price = price.find('p')
if price:
price = price.text
for cases in collection:
cases = cases.find('p')
if price:
cases = cases.text
print(title.text, price.text, collection.text)
webscrape()
Возвращает:
print(title.text, price.text, collection.text)
AttributeError: 'NoneType' object has no attribute 'text'
Я хочу, чтобы он возвращал три значения по порядку. EG Containment Breach '\ n' A $ 40,57 -A $ 271,90 '\ n' Расколотое дело
и так далее. У некоторых скинов есть 2 набора цен, и я хочу, чтобы оба набора цен были распечатаны.
Я получил его больше, чтобы показать, с чем я борюсь
from bs4 import BeautifulSoup
import requests
import urllib3
urllib3.disable_warnings()
def webscrape():
url = "https://csgostash.com/weapon/AWP"
res = requests.get(url = url)
soup = BeautifulSoup(res.text, "html.parser")
names = " "
price = " "
cases = " "
titles = soup.find_all('div', class_="well result-box nomargin")
prices = soup.find_all('div', class_="price")
collection = soup.find_all('div', class_="collection")
for name in titles:
a_field = name.find('a')
if a_field:
names = a_field.text + '\n' + names
for money in prices:
p_field = money.find('p')
if p_field:
price = p_field.text + '\n' + price
for case in collection:
case_field = case.find('p')
if case_field:
cases = case_field.text + '\n' + cases
print(names, price, cases)
webscrape()
Это печатает вся информация, которую я ищу на веб-странице, но я хочу, чтобы информация была сгруппирована, как если бы я хотел, чтобы цены и коллекция для скина печатались под именем скина. Прямо сейчас он печатает все имя, затем все цены, а затем все коллекции.