@@ -24,39 +24,43 @@ async def test_amazon_products():
2424 client = BrightDataClient ()
2525
2626 async with client .engine :
27- print ("\n 🛒 Testing Amazon product scraping..." )
28- print ("📍 Product URL: https://www.amazon.com/dp/B0CRMZHDG8" )
27+ scraper = client .scrape .amazon
28+ async with scraper .engine :
29+ print ("\n 🛒 Testing Amazon product scraping..." )
30+ print ("📍 Product URL: https://www.amazon.com/dp/B0CRMZHDG8" )
2931
30- try :
31- result = await client . scrape . amazon .products_async (
32+ try :
33+ result = await scraper .products_async (
3234 url = "https://www.amazon.com/dp/B0CRMZHDG8" ,
3335 timeout = 240
3436 )
3537
36- print (f"\n ✅ API call succeeded" )
37- print (f"⏱️ Elapsed: { result .elapsed_ms ():.2f} ms" if result .elapsed_ms () else "" )
38-
39- print (f"\n 📊 Result analysis:" )
40- print (f" - result.success: { result .success } " )
41- print (f" - result.data type: { type (result .data )} " )
42-
43- if result .data :
44- print (f"\n ✅ Got product data:" )
45- if isinstance (result .data , dict ):
46- print (f" - Title: { result .data .get ('title' , 'N/A' )} " )
47- print (f" - Price: { result .data .get ('price' , 'N/A' )} " )
48- print (f" - ASIN: { result .data .get ('asin' , 'N/A' )} " )
49- print (f" - Rating: { result .data .get ('rating' , 'N/A' )} " )
50- print (f" - Review Count: { result .data .get ('reviews_count' , 'N/A' )} " )
38+ print (f"\n ✅ API call succeeded" )
39+ print (f"⏱️ Elapsed: { result .elapsed_ms ():.2f} ms" if result .elapsed_ms () else "" )
40+
41+ print (f"\n 📊 Result analysis:" )
42+ print (f" - result.success: { result .success } " )
43+ print (f" - result.data type: { type (result .data )} " )
44+ print (f" - result.status: { result .status if hasattr (result , 'status' ) else 'N/A' } " )
45+ print (f" - result.error: { result .error if hasattr (result , 'error' ) else 'N/A' } " )
46+
47+ if result .data :
48+ print (f"\n ✅ Got product data:" )
49+ if isinstance (result .data , dict ):
50+ print (f" - Title: { result .data .get ('title' , 'N/A' )} " )
51+ print (f" - Price: { result .data .get ('price' , 'N/A' )} " )
52+ print (f" - ASIN: { result .data .get ('asin' , 'N/A' )} " )
53+ print (f" - Rating: { result .data .get ('rating' , 'N/A' )} " )
54+ print (f" - Review Count: { result .data .get ('reviews_count' , 'N/A' )} " )
55+ else :
56+ print (f" Data: { result .data } " )
5157 else :
52- print (f" Data: { result .data } " )
53- else :
54- print (f"\n ❌ No product data returned" )
58+ print (f"\n ❌ No product data returned" )
5559
56- except Exception as e :
57- print (f"\n ❌ Error: { e } " )
58- import traceback
59- traceback .print_exc ()
60+ except Exception as e :
61+ print (f"\n ❌ Error: { e } " )
62+ import traceback
63+ traceback .print_exc ()
6064
6165
6266async def test_amazon_reviews ():
@@ -69,45 +73,49 @@ async def test_amazon_reviews():
6973 client = BrightDataClient ()
7074
7175 async with client .engine :
72- print ("\n 📝 Testing Amazon reviews scraping..." )
73- print ("📍 Product URL: https://www.amazon.com/dp/B0CRMZHDG8" )
74- print ("📋 Parameters: pastDays=30, numOfReviews=10" )
75-
76- try :
77- result = await client .scrape .amazon .reviews_async (
76+ scraper = client .scrape .amazon
77+ async with scraper .engine :
78+ print ("\n 📝 Testing Amazon reviews scraping..." )
79+ print ("📍 Product URL: https://www.amazon.com/dp/B0CRMZHDG8" )
80+ print ("📋 Parameters: pastDays=30, numOfReviews=10" )
81+
82+ try :
83+ result = await scraper .reviews_async (
7884 url = "https://www.amazon.com/dp/B0CRMZHDG8" ,
7985 pastDays = 30 ,
8086 numOfReviews = 10 ,
8187 timeout = 240
8288 )
8389
84- print (f"\n ✅ API call succeeded" )
85- print (f"⏱️ Elapsed: { result .elapsed_ms ():.2f} ms" if result .elapsed_ms () else "" )
86-
87- print (f"\n 📊 Result analysis:" )
88- print (f" - result.success: { result .success } " )
89- print (f" - result.data type: { type (result .data )} " )
90-
91- if result .data :
92- if isinstance (result .data , list ):
93- print (f"\n ✅ Got { len (result .data )} reviews:" )
94- for i , review in enumerate (result .data [:3 ], 1 ):
95- print (f"\n Review { i } :" )
96- print (f" - Rating: { review .get ('rating' , 'N/A' )} " )
97- print (f" - Title: { review .get ('title' , 'N/A' )[:60 ]} ..." )
98- print (f" - Author: { review .get ('author' , 'N/A' )} " )
99- elif isinstance (result .data , dict ):
100- reviews = result .data .get ('reviews' , [])
101- print (f"\n ✅ Got { len (reviews )} reviews" )
90+ print (f"\n ✅ API call succeeded" )
91+ print (f"⏱️ Elapsed: { result .elapsed_ms ():.2f} ms" if result .elapsed_ms () else "" )
92+
93+ print (f"\n 📊 Result analysis:" )
94+ print (f" - result.success: { result .success } " )
95+ print (f" - result.data type: { type (result .data )} " )
96+ print (f" - result.status: { result .status if hasattr (result , 'status' ) else 'N/A' } " )
97+ print (f" - result.error: { result .error if hasattr (result , 'error' ) else 'N/A' } " )
98+
99+ if result .data :
100+ if isinstance (result .data , list ):
101+ print (f"\n ✅ Got { len (result .data )} reviews:" )
102+ for i , review in enumerate (result .data [:3 ], 1 ):
103+ print (f"\n Review { i } :" )
104+ print (f" - Rating: { review .get ('rating' , 'N/A' )} " )
105+ print (f" - Title: { review .get ('title' , 'N/A' )[:60 ]} ..." )
106+ print (f" - Author: { review .get ('author' , 'N/A' )} " )
107+ elif isinstance (result .data , dict ):
108+ reviews = result .data .get ('reviews' , [])
109+ print (f"\n ✅ Got { len (reviews )} reviews" )
110+ else :
111+ print (f" Data: { result .data } " )
102112 else :
103- print (f" Data: { result .data } " )
104- else :
105- print (f"\n ❌ No reviews data returned" )
106-
107- except Exception as e :
108- print (f"\n ❌ Error: { e } " )
109- import traceback
110- traceback .print_exc ()
113+ print (f"\n ❌ No reviews data returned" )
114+
115+ except Exception as e :
116+ print (f"\n ❌ Error: { e } " )
117+ import traceback
118+ traceback .print_exc ()
111119
112120
113121if __name__ == "__main__" :
0 commit comments