1. Винда 7
2. 3.8.6
Столкнулся с многими ошибками во время парсинга Авито.
2. 3.8.6
Столкнулся с многими ошибками во время парсинга Авито.
- list index out of range (147 строчка кода)
- Выдаёт даже те объявляения, которые спарсирились и некоторые вообще левые
Python:
def parsing_avito(message):
noytbuks = [] # здесь хранятся ноутбуки, которые уже спарсерены
houses = []
count = 0
print('Один из пользователей включил пассивный парсинг.')
url = 'https://www.avito.ru/kemerovo/noutbuki?s=104?cd=1?p=1'
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
house_data = html_soup.find_all('div', class_="item__line")
if house_data != []:
houses.extend(house_data)
print(house_data)
count += 1
else:
print('Ошибка №2. Скрипт парсинга авито.')
bot.send_message(message.chat.id, 'Случилась техническая ошибка. Просьба обратиться к системному администратору.')
count = 0 # обнуляем счётчик
while count <= 10:
print(str(count))
info = houses[int(count)]
price = info.find('span',{"class":"snippet-price"}).text
title = info.find('a',{"class":"snippet-link"}).text
url = "https://avito.ru" + info.find('a').get('href')
noytbuks.append(url)
print('' + str(noytbuks))
count += 1
while True:
count = 0
houses = []
scaled_value = random.uniform(3, 5)
time.sleep(scaled_value)
url = 'https://www.avito.ru/kemerovo/noutbuki?s=104?cd=1?p=1'
response = get(url)
html_soup = BeautifulSoup(response.text, 'html.parser')
house_data = html_soup.find_all('div', class_="item__line")
if house_data != []:
houses.extend(house_data)
else:
bot.send_message(message.chat.id, 'Случилась техническая ошибка. Просьба обратиться к системному администратору.')
print('Ошибка №5. Скрипт парсинга авито. Возможен бан.')
count = 0 # обнуляем счётчик
while count <= 10:
info = houses[int(count)]
price = info.find('span',{"class":"snippet-price"}).text
title = info.find('a',{"class":"snippet-link"}).text
url = "https://avito.ru" + info.find('a').get('href')
if(url in noytbuks):
a = 0
a =+ 1
else:
noytbuks.append(url);
bot.send_message(message.chat.id, 'Новое объявление:' + '\nНазвание:' + title + '\nЦена:' + price + '\nСсылка:' + str(url))
count += 1