ashwin kumar
ashwin kumar

Reputation: 1

How to Scrape data for mobile reviews in flipkart?

how to scrap the mobile reviews data from Flipkart

I tried using selenium package and but unable to extract all the reviews at a glance except for one review so can anyone help me with the code...

fk_path = ('[https://www.flipkart.com/moto-g-turbo-white-16-gb/product-
 reviews/itmecc4uhbue7ve6?pid=MOBECC4UQTJ5QZFR][1]')  
 from selenium import webdriver
 browser = webdriver.Chrome('/home/subhasis/chromedriver')  
 browser.get(fk_path)  
 browser.find_element_by_xpath("//span[@class='_1EPkIx']/span").click()  
 # Mimick clicking on 'Read More'
 [p.click() for p in browser.find_elements_by_xpath("//span[@class='_1EPkIx']/span")] # Expand 
 all 'Read More' buttons 
 browser.find_element_by_xpath("//div[@class='_3DCdKt']//div[@class='qwjRop']/div").text  
# Extract texts from respective Xpaths (1st review) 

Upvotes: 0

Views: 343

Answers (1)

allen-munsch
allen-munsch

Reputation: 54

Try opening a browser like firefox / chrome and checking the the xpath selection.

$x('//div[@class="col"]')
$x('//div[@class="col"]/*/*/p/text()')

Consider giving the browser some time to load all of the extra javascript as well before going through and clicking so quickly, this also prevents any timeouts that might occur because of getting blocked for making so many requests so quickly, consider between clicking "read more":

time.sleep(1)

The reason being is that it looks like it might make a network request when clicking read more.

enter image description here

Upvotes: 1

Related Questions