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