import requests
from bs4 import BeautifulSoup as bs
def parser():
file = open("test.txt", "w")
HOST = "https://www.avito.ru"
max_pages = 9
for x in range(1, max_pages + 1):
page = requests.get("https://www.avito.ru/moskovskaya_oblast_krasnogorsk/igry_pristavki_i_programmy?p=" + str( x ) )
soup = bs(page.content, "html.parser")
buys = []
items = soup.find_all("div", class_ = "snippet-horizontal")
for item in items:
buys.append({
"title": item.find("a", class_= "snippet-link").get_text(strip=True),
"link": HOST + item.find("a", class_="snippet-link").get("href"),
})
for i in buys:
print(i["title"])
print(i["link"])
file.write(i["title"])
file.write(i["link"])
file.close()
parser()
import requests
from bs4 import BeautifulSoup as bs
def parser():
file = open("test.txt", "w")
HOST = "https://www.avito.ru"
max_pages = 9
for x in range(1, max_pages + 1):
page = requests.get("https://www.avito.ru/moskovskaya_oblast_krasnogorsk/igry_pristavki_i_programmy?p=" + str( x ) )
soup = bs(page.content, "html.parser")
buys = []
items = soup.find_all("div", class_ = "snippet-horizontal")
for item in items:
title = item.find("a", class_= "snippet-link").get_text(strip=True)
link = item.find("a", class_="snippet-link").get("href")
print(f"{title} {HOST}{link}\n")
file.writelines(f"{title} {HOST}{link}\n")
file.close()
parser()