from bs4 import BeautifulSoup
import requests
import csv
CSV = 'cards.csv'
HOST = 'https://zeon18.ru'
URL = 'https://zeon18.ru/page/search/?name=%D0%A2%D0%B5%D1%80%D0%BC%D0%BE%D0%BF%D0%B0%D1%81%D1%82%D0%B0'
HEADERS = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041'
}
def get_html(url, params = 'params'):
r = requests.get(url, headers = HEADERS, params = params)
return r
def get_content(html):
soup = BeautifulSoup(html, 'html.parser')
items = soup.find_all('div', class_='catalog-grid-cell')
cards = []
for item in items:
cards.append(
{
'title':item.find('a', class_ = 'catalog-item-title').get_text(),
'brand':item.find('div', class_ = 'catalog-item-price-main').get_text()
}
)
return cards
def save_doc(items, path):
with open(path, "w", newline='') as file:
writer = csv.writer(file, delimiter=';')
writer.writerow()
writer.writerow(['Термопаста', 'Цена'])
for item in items:
writer.writerow([item['title'], item['brand']])
def parser():
PAGENATION = input('Укажите номер: ')
PAGENATION = int(PAGENATION.strip())
html = get_html(URL)
if html.status_code == 200:
cards = []
for p in range(1, PAGENATION):
print(f'Парсим страницу: {p}')
html = get_html(URL, params={'p' : p})
cards.extend(get_content(html.text))
save_doc(cards, CSV)
pass
else:
print('Error')
parser()
<Ошибка>
Traceback (most recent call last):
File "C:\python\main.py", line 53, in
parser()
File "C:\python\main.py", line 48, in parser
save_doc(cards, CSV)
File "C:\python\main.py", line 33, in save_doc
writer.writerow()
TypeError: writer.writerow() takes exactly one argument (0 given)
Ошибка>