Y
Y
YarNer2022-01-15 13:10:59
Python
YarNer, 2022-01-15 13:10:59

Why displays paragraphs with the word?

import requests
from bs4 import BeautifulSoup

a = 0

dollar_rub = 'https://www.avito.ru/rostovskaya_oblast?localPriority=0&q=Квартира'
headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.85 YaBrowser/21.11.4.730 Yowser/2.5 Safari/537.36'}

full = requests.get(dollar_rub, headers=headers)

soup = BeautifulSoup(full.content, 'html.parser')

convert = soup.findAll("span", {"class": "price-text-E1Y7h text-text-LurtD text-size-s-BxGpL"})


for i in convert:
  if 'месяц' not in i:
    print(convert[convert.index(i)].text)


Why does it still display elements with words on the last lines, how to fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Karbivnichy, 2022-01-15
@YarNer

Because i is not a drain, but bs4.element.Tag.
Try like this:
if 'месяц' not in i.text:

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question