Scrapping kaymu products using NOKOGIRI
scrapping kaymu products

It’s saturday morning and I have nothing interesting to do. So I thought of scraping Kaymu and list out products and their price using ruby. I targeted raspberry pi for this exercise.
Libraries I used are:
- <a href=https://github.com/jnunemaker/httparty rel=“nofollow” target=“_blank”>httparty to make http request
- <a href=https://github.com/sparklemotion/nokogiri rel=“nofollow” target=“_blank”>nokogiri to parse html
- <a href=https://github.com/pry/pry rel=“nofollow” target=“_blank”>pry for debugging
Here is the commented script:
# requiring dependencies
require 'nokogiri'
require 'httparty'
require 'pry'
# kaymu url to search raspberry pi and list them in ascending order of price
SITE = "http://www.kaymu.com.np/catalog/?q=raspberry+pi&sort=price&dir=asc"
# hitting the url to get data
page = HTTParty.get(SITE)
parse_page = Nokogiri::HTML(page)
products_array = []
# acquiring required data using Nokogiri's css methods
parse_page.css('.row-products .product').each do |product|
products_array.push({item: product.css('h3').text, price: product.css('.price').text})
end
p products_arrayOutput:
[
{:item => "Raspberry Pi Lcd 3.5 inch", :price => "Rs 3,500 "},
{:item => "Raspberry Pi 3.5” TFT with Touch Screen", :price => "Rs 3,970 "},
{:item => "Raspberry Pi - 2 Camera", :price => "Rs 4,669 "},
{:item => "Raspberry PI Model B+", :price => "Rs 5,900 "},
{:item => "Raspberry Pi Model B+", :price => "Rs 6,330 "},
{:item => "Raspberry Pi-2 B Plus with Casing", :price => "Rs 6,899 "},
{:item => "5 inch HDMI Touch Screen for Raspberry Pi", :price => "Rs 7,200 "},
{:item => "Raspberry Pi 3", :price => "Rs 7,300 "},
{:item => "Raspberry Pi 3 (Made in UK)", :price => "Rs 8,299 "},
{:item => "Raspberry Pi 3 Model B", :price => "Rs 8,500 "}
]If you want to learn scrapping yourself, <a href=https://www.distilled.net/resources/web-scraping-with-ruby-and-nokogiri-for-beginners/ rel=“nofollow” target=“_blank”>you can follow better tutorial here.
Keep reading

Fix mise GitHub Rate Limit with a Token
mise makes unauthenticated GitHub API calls by default. When you hit the rate limit installing tools, a personal access token (no scopes required) fixes it permanently.

How to solve Deployment Failure-`assets:precompile`
I was trying to deploy rails 6 app on ec2 server using capistrano when precompile failure lead to whole deploymentt failure. I had to uninstall cmdtest and install yarn

How to Sort an Array of Objects in JavaScript
How to Sort an Array of Objects in JavaScript

What did you take away?
Thoughts, pushback, or a story of your own? Drop a reply below — I read every one.
Comments are powered by Disqus. By posting you agree to theirterms.