При запуске парсера ничего не выводится
При запуске парсера ничего не выводится
from bs4 import BeautifulSoup
import requests
def parce():
URL = 'https://www.olx.kz/elektronika/kompyutery-i-komplektuyuschie/q-Компьютеры/'
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 YaBrowser/21.9.0.1044 Yowser/2.5 Safari/537.36'
}
respons = requests.get(URL, headers = HEADERS)
soup = BeautifulSoup(respons.content, 'html.parser')
items = soup.findAll('div', class_ = 'offer promoted')
comps = []
for item in items:
comps.append({
"title": item.find('a', class_ = 'marginright5 link linkWithHash detailsLink linkWithHashPromoted').get_text(strip = True)
})
for comp in comps:
print(f'{comp["title"]}')
parce()
Ответы (1 шт):
Автор решения: Рамис
→ Ссылка
from bs4 import BeautifulSoup
import requests
def parce():
URL = 'https://www.olx.kz/elektronika/kompyutery-i-komplektuyuschie/q-Компьютеры/'
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 YaBrowser/21.9.0.1044 Yowser/2.5 Safari/537.36'
}
respons = requests.get(URL, headers = HEADERS)
soup = BeautifulSoup(respons.content, 'html.parser')
items = soup.find_all('td', {"class": "offer promoted"})
comps = []
for item in items:
title = item.find('h3', {"class":"lheight22 margintop5"}).text.replace('\n', '')
comps.append(title)
for i in comps:
print(i)
parce()
Все потому, что это не работает items = soup.findAll('div', class_ = 'offer promoted') и ваш список items пустой