简体   繁体   中英

Can't collect pagination

while page <= last_page

  pagination=("https://www.petsonic.com/snacks-huesos-para-perros/?=#{page}")
  puts pagination
  doc2=Nokogiri::HTML(Curl.get(pagination).body_str)

  links=doc2.xpath('//a[@class="product-name"]/@href')
  links.each do |url|
    doc3=Nokogiri::HTML(Curl.get(url).body_str)
    name1=doc3.xpath('//h1[@class="product_main_name"]').text
    puts name1
  end
  page +=1
end

However,for some reason it collects information from first page 4 times, instead of collection from all 4 pages. What might be the issue?

EDIT: i missed 'p' in pagination=("https://www.petsonic.com/snacks-huesos-para-perros/?p=#{page}")

Case closed

It is a simple typo. Just replace

pagination=("https://www.petsonic.com/snacks-huesos-para-perros/?=#{page}")

with

pagination=("https://www.petsonic.com/snacks-huesos-para-perros/?p=#{page}")

Note the p in the query params.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM