P
P
Penguinwtf2021-05-25 12:55:33
laptops
Penguinwtf, 2021-05-25 12:55:33

How to fix none item.find error when creating a dictionary?

I am doing my first parsing, as you can understand, from another video from YouTube. Until the moment when dictionaries are added, everything works properly, as soon as I try to distribute all the found soup into dictionaries, only "none" is written there, respectively, and the get function cannot be used.

import requests
from bs4 import BeautifulSoup

URL = 'https://www.wowprogress.com/gearscore/?lfg=1&raids_week=&lang=ru&sortby=ts'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36 OPR/75.0.3969.267', 'accept':'*/*'}

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

def get_content(html):
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.findAll('tabel', class_='rating')
    #print(items)
    chars = []
    for item in items:
       chars.append({
            'nick': item.find('tr', class_='hint--bottom-right'),
            'server': item.find('div', class_='realm'),
            'link': item.find('a', class_='hint--bottom-right').get_text('href')

        })
        print(chars)

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

parse()


*different item.find parameters for the test, there are 'a's everywhere on the page*

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim Andreevich, 2019-01-03
@Theon

It's called: 2.5/3.5 Drive Mounts/Sled for Notebook.

S
soremix, 2021-05-25
@Penguinwtf

table, and not tabel
Plus, you obviously want to find only one table, and already look for tr in it.
In general, there the table is slightly broken, the tag closes without opening. Better to lxmlswitch then.
Well, on the little things, the wrong blocks are clearly chosen.

def get_content(html):
    soup = BeautifulSoup(html, 'lxml')
    items = soup.find('table', class_='rating').find_all('tr')
    chars = []
    for item in items:
        chars.append({
            'nick': item.find('a', class_='hint--bottom-right').text,
            'server': item.find('a', class_='realm').text,
            'link': item.find('a', class_='hint--bottom-right').get('href')

        })
    print(chars)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question