2015-12-02 74 views
0

我是新来的铁轨,从来没有使用角js。我想从这个链接linkRails PhantomJS for scraping

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)  

回答

1

你并不需要添加Nokogirimechanize这里提取的价格和卖家的名称。 watir将获得你想要的所有元素。尝试运行下面的代码,它会解决你的问题。

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 
+0

嘿我粘贴它表示#错误未定义的方法'maximiz”的代码<的Watir ::窗口:0x75dcffacef69afd4位于=真> – Aniket

+0

确定jjust用'browser.window.maximize'忘E更改它那里:) –

+0

尝试从'browser = Watir :: Browser.new:phantomjs'中删除phantomjs并更改为'browser = Watir :: Browser.new',它将打开您的浏览器。看看网站是否在移动视图中加载 –