From 190afd4669c7c4fc3cfe82b7825913b07f27643b Mon Sep 17 00:00:00 2001 From: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Date: Mon, 7 Aug 2023 11:56:41 +0000 Subject: [PATCH 1/2] updating DIRECTORY.md --- DIRECTORY.md | 1 + 1 file changed, 1 insertion(+) diff --git a/DIRECTORY.md b/DIRECTORY.md index fdcf0ceedf1f..e6a1ff356143 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -585,6 +585,7 @@ * [Hardy Ramanujanalgo](maths/hardy_ramanujanalgo.py) * [Hexagonal Number](maths/hexagonal_number.py) * [Integration By Simpson Approx](maths/integration_by_simpson_approx.py) + * [Interquartile Range](maths/interquartile_range.py) * [Is Int Palindrome](maths/is_int_palindrome.py) * [Is Ip V4 Address Valid](maths/is_ip_v4_address_valid.py) * [Is Square Free](maths/is_square_free.py) From 8bfdd14d09cb9c908ed0ace8c1282d89edb893d7 Mon Sep 17 00:00:00 2001 From: CaedenPH Date: Wed, 16 Aug 2023 16:54:57 +0100 Subject: [PATCH 2/2] fix(get-amazon-product-data): Remove whitespace in headers --- Amazon Product Data for headphones.csv | 1 + web_programming/get_amazon_product_data.py | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 Amazon Product Data for headphones.csv diff --git a/Amazon Product Data for headphones.csv b/Amazon Product Data for headphones.csv new file mode 100644 index 000000000000..42329c02b86e --- /dev/null +++ b/Amazon Product Data for headphones.csv @@ -0,0 +1 @@ +,Product Title,Product Link,Current Price of the product,Product Rating,MRP of the product,Discount diff --git a/web_programming/get_amazon_product_data.py b/web_programming/get_amazon_product_data.py index c796793f2205..9bd67f726a53 100644 --- a/web_programming/get_amazon_product_data.py +++ b/web_programming/get_amazon_product_data.py @@ -19,11 +19,13 @@ def get_amazon_product_data(product: str = "laptop") -> DataFrame: """ url = f"https://www.amazon.in/laptop/s?k={product}" header = { - "User-Agent": """Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 - (KHTML, like Gecko)Chrome/44.0.2403.157 Safari/537.36""", + "User-Agent": ( + "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36" + "(KHTML, like Gecko)Chrome/44.0.2403.157 Safari/537.36" + ), "Accept-Language": "en-US, en;q=0.5", } - soup = BeautifulSoup(requests.get(url, headers=header).text) + soup = BeautifulSoup(requests.get(url, headers=header).text, features="lxml") # Initialize a Pandas dataframe with the column titles data_frame = DataFrame( columns=[ @@ -74,8 +76,8 @@ def get_amazon_product_data(product: str = "laptop") -> DataFrame: except ValueError: discount = float("nan") except AttributeError: - pass - data_frame.loc[len(data_frame.index)] = [ + continue + data_frame.loc[str(len(data_frame.index))] = [ product_title, product_link, product_price, @@ -97,4 +99,8 @@ def get_amazon_product_data(product: str = "laptop") -> DataFrame: if __name__ == "__main__": product = "headphones" - get_amazon_product_data(product).to_csv(f"Amazon Product Data for {product}.csv") + print( + get_amazon_product_data(product).to_csv( + f"Amazon Product Data for {product}.csv" + ) + )