Created
September 4, 2013 22:13
-
-
Save rskelley9/6443550 to your computer and use it in GitHub Desktop.
not finished
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'nokogiri' | |
require_relative 'util' | |
class Browser | |
def run! | |
# Run the browser | |
# Display a prompt for a user | |
# Parse their input | |
# Display useful results by instantiating | |
# a new Page and calling methods on it. | |
# Questions: | |
# 1. How can a user quit the browser gracefully? | |
# 2. How can a user ask for help, i.e., how do they know what commands are available to them? | |
end | |
end | |
Browser.new.run! | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'nokogiri' | |
class Page | |
def initialize(url) | |
@links = doc.search(url)('.body> a:first_child').map{|link| link} | |
@uri = URI.parse(url) | |
@title = doc.search('.title > a:first-child').map { |link| link.inner_text} | |
@doc = Nokogiri::HTML(open('post.html')) | |
@title = doc.search('.title > a:first-child').map { |link| link.inner_text} | |
@points = doc.search('.subtext > span:first-child').map { |span| span.inner_text} | |
@comments = doc.search('.comment > font:first-child').map { |font| font.inner_text} | |
@link = doc.search('.title > a:first-child').map { |link| link['href']} | |
@item_id = doc.search('.subtext > a:nth-child(3)').map {|link| link['href'] } | |
@comment = Comment.new('Steve', '200', 'You would be surprised at what you can achieve with a little effort and using mainly smaller companies with an ethical bent (certainly ethical clothing and bicycles are available). | |
Nevertheless, I agree it is hard, and I.') | |
end | |
def fetch! | |
end | |
def title | |
@title | |
end | |
def links | |
# Research alert! | |
# How do you use Nokogiri to extract all the link URLs on a page? | |
# | |
# These should only be URLs that look like | |
# <a href="http://somesite.com/page.html">Click here!</a> | |
# This would pull out "http://somesite.com/page.html" | |
end | |
end | |
new_page = Page.new('https://news.ycombinator.com/item?id=5003980') | |
# puts "Hi, please input a url: " | |
# url_input = gets.chomp | |
# Net::HTTP.get_print(uri) #==> returns response page body | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment