Rails 用于抓取的 PhantomJS

Rails PhantomJS for scraping

我是 rails 的新手,从未使用过 angular js。我想从这个 link link

中提取价格和卖家名称
module HomesHelper
require 'selenium-webdriver'
require 'mechanize'
require 'nokogiri'
require 'phantomjs'
require 'watir'

b = Watir::Browser.new(:phantomjs)

b.goto url
doc = Nokogiri::HTML(b.html)    

您不需要在此处添加 Nokogirimechanizewatir 将获得您想要的所有元素。尝试 运行 下面的代码,它将解决您的问题。

require 'selenium-webdriver'
require 'phantomjs'
require 'watir'

browser = Watir::Browser.new :phantomjs
browser.window.maximize
browser.goto "https://paytm.com/shop/p/gionee-e7-mini-black-MOBGIONEE-E7-MIHAPP44414CBBDB36C?psearch=organic|undefined|gionee%20e7|grid"
puts browser.div(:class => 'profile-description').a.h2.text
puts browser.div(:class => 'buy-bar').button.span.text
puts browser.div(:class => 'effPrc').span.text
browser.close