from bs4 import BeautifulSoup
import requests
import time
import pymysql
import numpy
import sys
import os
global headers
global query
query = input('Item name? ')
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.92 YaBrowser/19.10.0.1522 Yowser/2.5 Safari/537.36'}
def nextpage(page, qur):
arr[]
currentpage = page
web = requests.get('https://www.avito.ru/ekaterinburg?p={0}&q={1}'.format(page, qur), headers=headers)
parse = BeautifulSoup(web.text, 'html.parser')
def getcurrentpage():
nonlocal currentpage
currentpage += 1
return currentpage
for tag in parse.find_all('span', class_='price'):
try:
price = tag.text
price = price.replace('₽', '')
price = price.replace(' ', '')
price = int(price)
arr.append(price)
meanarr = numpy.mean(arr)
os.system('cls')
sys.stdout.write("\rСредняя цена: {0}, Текущая страница: {1}".format(meanarr, currentpage))
sys.stdout.flush()
except ValueError:
pass
getcurrentpagef = getcurrentpage()
nextpage(getcurrentpagef, qur)
nextpage(1, query)
'A' + str[0:]