Can Nokogiri interpret javascript? - Web Scraping

折月煮酒 提交于 2019-12-01 07:35:59

Nokogiri is just a parser. It also allows to search content.

To interact with web pages you need to use something else, e.g. Watir and PhantomJS.

Combining them all together:

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

browser.goto(your_url_above)
browser.link(text: 'All floorplans').click

document = Nokogiri::HTML(browser.html)
document.search(...)
Milind

Yes, you can do it if the Floorplans have an id/class. You can get those from your page.

You will be needing firepath to help you get the XPath of the elements and then you can iterate them using it. For example, recently I worked on webpagescraper to scrape HTML from fundly.com.

To get all titles, as all titles elements in the HTML had the same class, I was able to get EVERY title on https://fundly.com/search/%60 using that XPath with the class name like:

require 'rubygems'
require 'nokogiri'
require 'open-uri'

doc.search('h4.f-width-100').each do |title|
   @campaign_titles <<  title.text
end  

Please refer to my above project if you need any more assistance to grab the values from any website.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!