22from bs4 import BeautifulSoup
33
44# scraping amazon product page
5+
6+
57class Product :
68 def __init__ (self , product_name : str ):
79 self .product_name = product_name
810
911 def get_product (self ):
10-
12+
1113 try :
1214 product_name = self .product_name
1315 product_name = product_name .replace (" " , "+" )
@@ -19,7 +21,8 @@ def get_product(self):
1921 r = requests .get (url , headers = headers )
2022 soup = BeautifulSoup (r .content , "html.parser" )
2123 product = soup .find ("div" , {"class" : "s-product-image-container" })
22- product_link = product .find ("a" , {"class" : "a-link-normal" })["href" ]
24+ product_link = product .find (
25+ "a" , {"class" : "a-link-normal" })["href" ]
2326 product_link = "https://www.amazon.in" + product_link
2427 return {
2528 "data" : product_link ,
@@ -57,8 +60,10 @@ def get_product_details(self):
5760 }
5861 r = requests .get (product_link , headers = headers )
5962 soup = BeautifulSoup (r .content , "html.parser" )
60- product_name = soup .find ("span" , {"id" : "productTitle" }).text .strip ()
61- product_price = soup .find ("span" , {"class" : "a-price-whole" }).text .strip ()
63+ product_name = soup .find (
64+ "span" , {"id" : "productTitle" }).text .strip ()
65+ product_price = soup .find (
66+ "span" , {"class" : "a-price-whole" }).text .strip ()
6267 product_rating = soup .find (
6368 "span" , {"class" : "a-size-base a-color-base" }
6469 ).text .strip ()
@@ -165,7 +170,8 @@ def customer_review(self):
165170 review_text = review_element .find (
166171 "span" , {"data-hook" : "review-body" }
167172 ).text .strip ()
168- review = [reviewer_name , rating , review_title , review_date , review_text ]
173+ review = [reviewer_name , rating ,
174+ review_title , review_date , review_text ]
169175 return {
170176 "data" : review ,
171177 "message" : f"Product review has been fetched" ,
0 commit comments