Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- This is an attempt to write a spider
- start off with requiring gems. then parse a html file
- by connecting to a server and using nokogiri to parse the html
- into a variable!
- =end
- require 'rubygems'
- require 'nokogiri'
- require 'open-uri'
- =begin
- create a method to accept a link from the user and return how many
- links are present in the url given
- =end
- def howManyLinks()
- #local links array
- links =[]
- #get the name of link you wanna crawl from the user
- link= gets.chomp
- #use nokogiri to parse the html from the uri
- doc = Nokogiri::HTML(open(link))
- #find all the links in the uri and add them to the local array
- #links!
- doc.css("a").each do |l|
- links.push(l.content)
- end
- #print the outcome
- puts "The spider found #{links.count} links"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement