2015-12-02 47 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',它將打開您的瀏覽器。看看網站是否在移動視圖中加載 –