G
G
goormany2021-07-29 22:32:58
Python
goormany, 2021-07-29 22:32:58

Why does the parser output only 1 number?

So hello, I'm trying to create a parser for the site ' https://csgopolygon.gg ' (NOT ADVERTISING)
They say that you need to check all your steps and here is the problem, it displays 1 number, this is the number 7 (although it is not in the number drop feed )

Here is the code:

from bs4 import BeautifulSoup
import requests

URL = 'https://csgopolygon.gg'
HEADERS = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.164 Safari/537.36 OPR/77.0.4054.275 (Edition Yx GX)'
}

def get_html(url):
    r = requests.get(url, headers=HEADERS)
    return r

def get_content(html):
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('ul', class_='balls')

    ballz = []

    for item in items:
        ballz.append({
            'num': item.find('li', class_='ball').get_text(strip=True)
        })
        print(ballz)

def parse():
    html = get_html(URL)
    if html.status_code == 200:
        get_content(html.text)
    else:
        print(html.status_code)

parse()


Here's the output:
6103029c58deb832257849.png
Here's what's on the site:
610302a505887638737824.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stefan, 2021-07-30
@MEDIOFF

You look on the page for all uls with the balls class, such as I understand only one, then in the loop you take this one ul and look for li with the ball class from it, it finds the first one it found and returns.
As I see the solution:
1. In the loop, make a nested loop that will go through all li;
2. Instead of ul balls, take all li balls at once.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question