Skip to content

Commit 7c76ed6

Browse files
Merge pull request #2484 from alwenpy/mosaic
Mosaic Augmentation
2 parents 318c2fb + 5ae3723 commit 7c76ed6

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

Amazon_product_scraper/products.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import requests
22
from bs4 import BeautifulSoup
33

4-
# scraping amazon product page
5-
6-
74
class Product:
85
def __init__(self, product_name: str):
96
self.product_name = product_name
107

118
def get_product(self):
12-
139
try:
1410
product_name = self.product_name
1511
product_name = product_name.replace(" ", "+")
@@ -60,10 +56,8 @@ def get_product_details(self):
6056
}
6157
r = requests.get(product_link, headers=headers)
6258
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()
6761
product_rating = soup.find(
6862
"span", {"class": "a-size-base a-color-base"}
6963
).text.strip()
@@ -170,8 +164,7 @@ def customer_review(self):
170164
review_text = review_element.find(
171165
"span", {"data-hook": "review-body"}
172166
).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]
175168
return {
176169
"data": review,
177170
"message": f"Product review has been fetched",

0 commit comments

Comments
 (0)