I have the following function, which I intend to extend it:
def get_dataframe(site, search):
if site == 'pichau':
try:
soup = get_page(f'https://www.pchau.com.br/catalogsearch/result/?q={search}')
assert soup
price_cartao = [i.getText() for i in soup.select('.other .valor')]
price_boleto = [i.getText().replace('à vista', '') for i in soup.select('.boleto .valor')]
product = [i.get('title').upper() for i in soup.select('.title a')][:len(price_cartao)]
data = {'Produto': product, 'Preço à vista': price_boleto, 'Preço cartão': price_cartao}
product_df = DataFrame(data)
return product_df
except Exception as e:
return 'Problema com a conexão entre o site!'
elif site == 'chipart':
try:
soup = get_page(f'https://www.chipart.com.br/produtos/{search}')
assert soup
price_boleto = [i.getText() for i in soup.select('.products__list__item .product-card__price__final .price')]
price_cartao1 = [i.getText().strip().replace('\t', '').replace('\n', '').replace('em', '') for i in soup.select('.products__list__item .installments')]
price_cartao2 = [i.getText() for i in soup.select('.products__list__item .price-installments .price')]
product = [i.getText().strip().replace('\t', '').replace('\n', '') for i in soup.select('.product-card__title .title')][:len(price_boleto)]
price_cartao = [f'{price_cartao1[i]} de {price_cartao2[i]}' for i in range(len(price_boleto))]
data = {'Produto': product, 'Preço à vista': price_boleto, 'Preço cartão': price_cartao}
product_df = DataFrame(data)
return product_df
except Exception as e:
return 'Problema com a conexão entre o site!'
In this case, would the recommend be instead of breaking into several ifs "break it" into various functions?