0

How to scrape all reviews from walmart review page (ex:http://www.walmart.com/ip/Ematic-9-Dual-Screen-Portable-DVD-Player-with-Dual-DVD-Players-ED929D/28806789) if they are on different pages?I scrape by mechanize(nokogiri) but it can't click on button(it is not part of form,then I can't submit it)

<button class="paginator-btn paginator-btn-next"><span 
class="visuallyhidden">Next Page</span></button>

and I can't go to next page.How to solve this problem?

Ivan Skotsyk
  • 127
  • 2
  • 8

2 Answers2

1

Updated answer (post question edit):

I think it may be easier than that. If you pay attention to the product url, you see that there is some kind of ID at the end of the url:

http://www.walmart.com/ip/Ematic-9-Dual-Screen-Portable-DVD-Player-with-Dual-DVD-Players-ED929D/28806789

If you get that ID, you could take the reviews root page (https://www.walmart.com/reviews/product/) and concat the ID of the product:

https://www.walmart.com/reviews/product/28806789

Now, you can iterate over the products, take the trailing ID, and go to each reviews page to get all the reviews.

Hope it helped.

Old answer (pre question edit):

The page you posted is empty for me. However, what I see is that the element is a button, therefore, what you need to do is look for the form and then submit it.

Example taken from Clicking a button with Ruby mechanize (in case the link stops working for some reason):

# get the form
form = agent.page.form_with(:name => "my-form")
# get the button you want from the form
button = form.button_with(:value => "Search")
# submit the form using that button
agent.submit(form, button)

Credit to @flaviu and @serabe from the question stated.

To do the scraping, you should save the root url and go to the review pages, get the reviews, go back to the root url, and so on.

Unai Sanchez
  • 496
  • 1
  • 6
  • 14
  • This button is not part of form,and I can t submit it – Ivan Skotsyk Oct 02 '18 at 09:04
  • Question isn't answered.I know how to go to the reviews page,but it has a lot of reviews pages and I need to click button "next page".After click this button ,url not change (then i can't iterate it).Only content change – Ivan Skotsyk Oct 02 '18 at 10:24
  • Yeah, I realised it after I posted the updated version of my answer. If I can come up with a solution, I'll tell you.However, could you post the code of what you've tried so far? – Unai Sanchez Oct 02 '18 at 10:37
0

I solve this task with watir gem.Mechanize cant interact with JavaScript.

Ivan Skotsyk
  • 127
  • 2
  • 8