为什么PhantomJS / Poltergeist无法正确拉动这个网站?

时间:2015-06-03 18:44:34

标签: ruby phantomjs capybara poltergeist

我使用Capybara导航网页。网址看起来像这样:

http://www.myapp.com/page/ABCXYZ?page=<x>

页面上有一个分页表。将页码传递给它将适当地对表格进行分页。

但是,使用poltergeist驱动程序时,始终会忽略page参数。

使用selenium驱动程序不是一种选择,因为让它运行无头是很麻烦的,它不想运行多次(给出&#34;连接被拒绝& #34; localhost错误。)

这看起来像编码问题,但我不确定问题所在的堆栈究竟在哪里。

class Verifier
  class << self

    include Capybara::DSL
    Capybara.default_driver = :poltergeist
    Capybara.default_wait_time = 10

    def parse_table(header)
      xpath = '//*[@id="products"]/table[3]/tbody/tr/td/div[4]/div/table'
      table = find(:xpath, xpath)
      rows = []
      table.all("tr").each do |row|
        product_hash = {}
        row.all("td").each_with_index do |col,idx|
          product_hash[header[idx]] = col.text
        end
        rows << product_hash
      end
      rows
    end

    def pages
      page.find(".numberofresults").text.gsub(" Products","").split(" ").last.to_i/25
    end

    def import(item)

      visit "http://www.myapp.com/page/#{item}"

      header = parse_header
      apps = parse_vehicles(header)
      pages.times do |pagenumber|
        url = "http://www.myapp.com/page/#{item}?page=#{pagenumber+1}" # This is the problem
      end

    end
  end

最后一个循环中的那个url?它的过程就像页面编号不存在一样。当我将驱动程序更改为:selenium时,整个过程都有效。因此,就我所见,它不是水豚问题。

0 个答案:

没有答案