RLeonid-777
Почетный гость
Добрый день. Помогите пожалуйста найти ошибки в коде на python
from bs4 import BeautifulSoup
import requests
def save():
with open("parse_info.txt", "a") as file:
file.write(f'{comp["title"]} -> Link:{comp["link"]}\n')
def parse():
URL="https://www.avito.ru/kemerovo/kvartiry"
HEADERS = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173 (Edition Yx)"
}
response=requests.get(URL, headers=HEADERS)
soup=BeautifulSoup(response.contant, "html.parser")
items=soup.findAll("div", class_="item__line")
comps=[]
for item in items:
comps.append({
"title": item.find("a", class_="snippert-link").get_text(strip=True),
"link":item.find("a", class_="snippert-link").get("href")
})
global comp
for comp in comps:
print(f'{comp["title"]} -> Link:{comp["link"]}')
save()
parse()
Это простой парсер, но он почему-то не работает
from bs4 import BeautifulSoup
import requests
def save():
with open("parse_info.txt", "a") as file:
file.write(f'{comp["title"]} -> Link:{comp["link"]}\n')
def parse():
URL="https://www.avito.ru/kemerovo/kvartiry"
HEADERS = {
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36 OPR/68.0.3618.173 (Edition Yx)"
}
response=requests.get(URL, headers=HEADERS)
soup=BeautifulSoup(response.contant, "html.parser")
items=soup.findAll("div", class_="item__line")
comps=[]
for item in items:
comps.append({
"title": item.find("a", class_="snippert-link").get_text(strip=True),
"link":item.find("a", class_="snippert-link").get("href")
})
global comp
for comp in comps:
print(f'{comp["title"]} -> Link:{comp["link"]}')
save()
parse()
Это простой парсер, но он почему-то не работает