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