Unexpected indent
Statement expected, found Py:DEDENT
Variable in function should be lowercase
Variable in function should be lowercase
Global variable 'comp' is undefined at the module level
Typo: In word 'KHTML'
Typo: In word 'marginright'
Typo: In word 'marginright'
from bs4 import BeautifulSoup
import requests
def save():
with open('parse_info.txt', 'a') as file:
file.write(f'{comp["title"]} -> Price: {comp["price"]} -> Link: {comp["link"]}\n')
def parse():
URL = 'https://www.olx.kz/transport/legkovye-avtomobili/'
HEADERS = {
'User-Agent': '&&&'
}
response = requests.get(URL, headers = HEADERS)
soup = BeautifulSoup(response.content, 'html.parser')
items = soup.findAll('div', class_ = 'offer-wrapper')
comps = []
for item in items:
comps.append({
'title': item.find('a', class_ = 'marginright5 link linkWithHash detailsLink linkWithHashPromoted').get_text(strip = True),
'price': item.find('p', class_ = 'price').get_text(strip = True),
'link': item.find('a', class_ = 'marginright5 link linkWithHash detailsLink linkWithHashPromoted').get('href')
})
global comp
for comp in comps:
print(f'{comp["title"]} -> Price: {comp["price"]} -> Link: {comp["link"]}')
save()