Answer the question
In order to leave comments, you need to log in
Why is the xpath query outputting 20 repetitions?
There is a page with a list of products. You need to pull out a link to each product. ( https://www.petsonic.com/snacks-huesos-para-perros/)
The expression I made prints all the links, but repeats 20 times. Where is the error in the expression?
(doc / "//div[@class='left-block']/div/*").each do |row|
product_link = (row / "//a[@class='product_img_link']/@href")
puts product_link
Answer the question
In order to leave comments, you need to log in
Probably the first expression selects 20 products and enters the loop
AND the second expression also selects 20 products
ps Why not select links right away?
//div[@class='left-block']/div//a[@class='product_img_link']/@href
//div[@class="productlist"]//a[@class="product- name"]/@href
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question