Ошибка при использовании pandas concat
from lxml.html import fromstring
from urllib.parse import urljoin
from lxml import etree
from numpy import FLOATING_POINT_SUPPORT
import requests
from pandas import DataFrame, ExcelWriter
import string
import pandas as pd
def get_html(url):
result = requests.get(url).text
f = fromstring(result)
return f
def get_data(html):
df = pd.DataFrame(columns=('Раздел 1', 'Описание раздела 1', 'симвовольный код 1', 'title 1', 'description 1', 'keywords 1',
'Раздел 2', 'Описание раздела 2', 'симвовольный код 2', 'title 2', 'description 2', 'keywords 2',
'Наименование элемента', 'Хлебные крошки', 'url', 'title 1', 'Детальное описание', 'Видео', 'Старая цена', 'Новая цена'))
for product in html.cssselect('.product-container'):
a = product.cssselect('a')[0]
href = a.get('href')
ar = requests.get(href).text
af = fromstring(ar)
bread1 = af.cssselect('.breadcrumb a')[2].text_content()
bread2 = af.cssselect('.breadcrumb a')[3].text_content()
breadcrumb = af.cssselect('.breadcrumb')[0].text_content()
title = af.cssselect('#product-name-wrap h1')[0].text_content()
price = af.cssselect('#our_price_display')[0].text_content()
opis = af.cssselect('.product-info-partblock')[0]
description = etree.tostring(opis, encoding='utf-8').decode('utf-8')
try:
video = af.cssselect('.product-info-partblock')[3]
vedios = etree.tostring(video, encoding='utf-8').decode('utf-8')
except IndexError:
vedios = ''
test = ''
klevielodki_list = [('Раздел 1', test),
('Описание раздела 1', test),
('симвовольный код 1', test),
('title 1', test),
('description 1', test),
('Раздел 2', test),
('Описание раздела 2', test),
('симвовольный код 2', test),
('title 2', test),
('description 2', test),
('keywords 2', test),
('Наименование элемента', title),
('Хлебные крошки', breadcrumb),
('url', href),
('title 1', title),
('Детальное описание', description),
('Видео', vedios),
('Старая цена', price),
('Новая цена', test)]
for xarik in af.cssselect('.product-info-content tr'):
alfa = xarik.cssselect('td')[0].text_content()
beta = xarik.cssselect('td')[1].text_content()
klevielodki_list.append((alfa, beta))
img = 0
for images in af.cssselect('#thumbs_list_frame li'):
ia = images.cssselect('a')[0]
ih = ia.get('href')
lir = requests.get(ih)
out = open('img/%s' % ih.split('/')[-2]+'.jpg', 'wb')
out.write(lir.content)
out.close()
img += 1
klevielodki_list.append(('img%s' % img, ih.split('/')[-2]+'.jpg'))
df = pd.concat(klevielodki_list, ignore_index=True)
print(df)
writer = ExcelWriter('клевыелодки.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='1', header=True, index=False)
writer.save()
def main():
html = get_html('https://klevielodki.ru/12-modeli-lodok/?id_category=12&n=245')
get_data(html)
if __name__ == "__main__":
main()
парсю сайт, у меня выходит ошибка, помогите пожалуйста
Exception has occurred: TypeError cannot concatenate object of type '<class 'tuple'>'; only Series and DataFrame objs are valid File "/home/artddss/python/em/bicom/klevielodki.py", line 86, in get_data df = pd.concat(klevielodki_list, ignore_index=True) File "/home/artddss/python/em/bicom/klevielodki.py", line 99, in main get_data(html) File "/home/artddss/python/em/bicom/klevielodki.py", line 103, in main() TypeError: cannot concatenate object of type '<class 'tuple'>'; only Series and DataFrame objs are valid
Источник: Stack Overflow на русском