|
1 | 1 | import requests
|
2 | 2 | from bs4 import BeautifulSoup
|
3 | 3 |
|
| 4 | + |
4 | 5 | class Product:
|
5 | 6 | def __init__(self, product_name: str):
|
6 | 7 | self.product_name = product_name
|
@@ -56,8 +57,10 @@ def get_product_details(self):
|
56 | 57 | }
|
57 | 58 | r = requests.get(product_link, headers=headers)
|
58 | 59 | soup = BeautifulSoup(r.content, "html.parser")
|
59 |
| - product_name = soup.find("span", {"id": "productTitle"}).text.strip() |
60 |
| - product_price = soup.find("span", {"class": "a-price-whole"}).text.strip() |
| 60 | + product_name = soup.find( |
| 61 | + "span", {"id": "productTitle"}).text.strip() |
| 62 | + product_price = soup.find( |
| 63 | + "span", {"class": "a-price-whole"}).text.strip() |
61 | 64 | product_rating = soup.find(
|
62 | 65 | "span", {"class": "a-size-base a-color-base"}
|
63 | 66 | ).text.strip()
|
@@ -164,7 +167,8 @@ def customer_review(self):
|
164 | 167 | review_text = review_element.find(
|
165 | 168 | "span", {"data-hook": "review-body"}
|
166 | 169 | ).text.strip()
|
167 |
| - review = [reviewer_name, rating, review_title, review_date, review_text] |
| 170 | + review = [reviewer_name, rating, |
| 171 | + review_title, review_date, review_text] |
168 | 172 | return {
|
169 | 173 | "data": review,
|
170 | 174 | "message": f"Product review has been fetched",
|
|
0 commit comments