manage exception when no description

This commit is contained in:
yann 2024-11-14 13:19:21 +01:00
parent 2bbf684c26
commit 4247f1ac83

View File

@ -32,8 +32,13 @@ def get_image_url(soup, url):
# get full description as string # get full description as string
# luckily this <p> was the only one without class # luckily this <p> was the only one without class
# and manage the case where there's no description
def product_description(soup): def product_description(soup):
desc = soup.find("p", class_='').string try:
desc = soup.find("p", class_='').string
except AttributeError:
desc = "None"
return desc return desc
# get category from breadcrumb # get category from breadcrumb
@ -44,16 +49,19 @@ def get_category(soup):
# create a list with all information consecutively # create a list with all information consecutively
# /!\ don't know if that's the best way # /!\ don't know if that's the best way
def get_data(soup, url): def get_data(soup, url):
info = [url, product_information(soup)['UPC'], info = [
get_title(soup), url, product_information(soup)['UPC'],
product_information(soup)['Price (incl. tax)'], get_title(soup),
product_information(soup)['Price (excl. tax)'], product_information(soup)['Price (incl. tax)'],
product_information(soup)['Availability'], product_information(soup)['Price (excl. tax)'],
product_description(soup), product_information(soup)['Availability'],
get_category(soup), product_description(soup),
product_information(soup)['Number of reviews'], get_category(soup),
get_image_url(soup, url) product_information(soup)['Number of reviews'],
] get_image_url(soup, url)
]
return info return info
# write the file # write the file
@ -76,6 +84,7 @@ def data_output(info, file):
for i in info: for i in info:
writer.writerow(i) writer.writerow(i)
return file