Initial commit, refactored some things from original code and removed WP functionality
This commit is contained in:
32
bot/parser.py
Normal file
32
bot/parser.py
Normal file
@@ -0,0 +1,32 @@
|
||||
import helpers
|
||||
|
||||
def get_title(soup):
|
||||
try:
|
||||
title = soup.find("span", attrs={"id":'productTitle'})
|
||||
title_value = title.string
|
||||
title_string = title_value.strip()
|
||||
except AttributeError as err:
|
||||
helpers.logging.info(f"Couldn't get title: {err}")
|
||||
title_string = ""
|
||||
|
||||
return title_string
|
||||
|
||||
def get_price(soup):
|
||||
try:
|
||||
price = soup.find("span", attrs={'class':'a-offscreen'}).string.strip()
|
||||
# A veces mete el título en el precio
|
||||
if "€" not in price:
|
||||
price = "N/A"
|
||||
except AttributeError:
|
||||
price = "N/A"
|
||||
|
||||
return price
|
||||
|
||||
def get_image(soup):
|
||||
try:
|
||||
image = soup.find("img", attrs={'id':'landingImage'})
|
||||
image = image.get('src')
|
||||
except AttributeError:
|
||||
image = "N/A"
|
||||
|
||||
return image
|
||||
Reference in New Issue
Block a user