Задать вопрос
  • Добрый вечер, пытаюсь запустить парсер сайта, выдает ошибки, в чем проблема?

    @Arm0x
    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()
    parse()
    Ответ написан
    Комментировать