from bs4 import BeautifulSoup
import requests
def save():
with open("parse_info.txt", "a") as file:
file.write(comp["title"])
def parse():
URL = "https://www.avito.ru/saratov/bytovaya_elektronika"
HEADERS = {
"User-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36 OPR/85.0.4341.72 "
}
response = requests.get(URL, headers=HEADERS)
soup = BeautifulSoup(response.content, "html.parser")
items = soup.findAll('div', class_="iva-item-content-rejJg") #вставляем класс из сайта
comps = []
for item in items:
comps.append({
"title": item.find("a ", class_="link-link-MbQDP link-design-default-_nSbv title-root-zZCwT iva-item-title-py3i_ title-listRedesign-_rejR title-root_maxHeight-X6PsH").get_text(strip=True)
})
global comp
for comp in comps:
print(comp["title"])
save()
parse()