From b7cfb7879c4d123f417c725d6bf2580326fea11f Mon Sep 17 00:00:00 2001 From: Arham Noman Date: Wed, 16 Mar 2022 23:26:10 +0500 Subject: [PATCH] Added error handling in pandas numeric conversion --- timer_function.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/timer_function.py b/timer_function.py index 9b1c80c..dd71272 100644 --- a/timer_function.py +++ b/timer_function.py @@ -7,7 +7,7 @@ from bs4 import BeautifulSoup as soup from urllib.request import urlopen as uReq import pandas as pd -my_url = "YOUR_EBAY_LINK" # Change this to your ebay search url +my_url = "YOUR EBAY URL" # Change this to your search url def main(mytimer: func.TimerRequest) -> None: utc_timestamp = datetime.datetime.utcnow().replace( @@ -21,7 +21,6 @@ def main(mytimer: func.TimerRequest) -> None: page_soup = soup(page_html, 'html.parser') divs = page_soup.findAll('div',{'class':'s-item__details clearfix'}) - # Extract relevant data from the soup object prices = [] @@ -34,7 +33,7 @@ def main(mytimer: func.TimerRequest) -> None: # Clean data and save to a file for later use - prices = pd.DataFrame(pd.to_numeric(prices)) + prices = pd.DataFrame(pd.to_numeric(prices,errors='coerce')).dropna() name = "PS5" + str(utc_timestamp) +".csv" name = "".join( x for x in name if (x.isalnum() or x in "._- ")) prices.to_csv(name) -- libgit2 0.26.0