how to parsing HTML with Nokogiri

Installation

Installation is very easy. Just add to your Gemfile.

gem "nokogiri"

Learn how to Generate HTML.

Quick start to parsing HTML

Parsing HTML is easy, and you can take advantage of CSS selectors or XPath queries to find things in your document:

require 'open-uri'
require 'nokogiri'

# Perform a google search
doc = Nokogiri::HTML(open('http://google.com/search?q=tenderlove'))

# Print out each link using a CSS selector
doc.css('h3.r > a.l').each do |link|
  puts link.content
end

Here is an example parsing some HTML and searching it using a combination of CSS selectors and XPath selectors:

require 'nokogiri'

doc = Nokogiri::HTML.parse(<<-eohtml)
<html>
  <head>
    <title>Hello World</title>
  </head>
  <body>
    <h1>This is an awesome document</h1>
    <p>
      I am a paragraph
        <a href="http://google.ca">I am a link</a>
    </p>
  </body>
</html>
eohtml

####
# Search for nodes by css
doc.css('p > a').each do |a_tag|
  puts a_tag.content
end

####
# Search for nodes by xpath
doc.xpath('//p/a').each do |a_tag|
  puts a_tag.content
end

####
# Or mix and match.
doc.search('//p/a', 'p > a').each do |a_tag|
  puts a_tag.content
end

###
# Find attributes and their values
doc.search('a').first['href']

Set Up SSH Keys

We use SSH keys to establish a secure connection between your computer and GitHub. Setting them up is fairly easy, but does involve a number of steps.

To make sure you generate a brand new key, you need to check if one already exists. First, you need to open an app called Terminal.
1. First, check for existing ssh keys on your computer:

cd ~/.ssh

2. Backup and remove existing SSH keys. Since there is already an SSH directory you’ll want to back the old one up and remove it:

$ ls
$ mkdir key_backup
$ cp id_rsa* key_backup
$ rm id_rsa*

3. Generate a new SSH key. To generate a new SSH key, enter the code below. We want the default settings so when asked to enter a file in which to save the key, just press enter.

$ ssh-keygen -t rsa -C "your_email@youremail.com"

Now you need to enter a passphrase.

Enter passphrase (empty for no passphrase):
Enter same passphrase again: