Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Can this scraper be simplified?
<pre class='prettyprint' language='ruby'>require 'rubygems' require 'net/http' require 'uri' def getbody(letter, pagenumber) url = URI.parse('http://www.somesite.com/') res = Net::HTTP.start(url.host, url.port) { |http| http.get("/browse.php?character=#{letter}&page=#{pagenumber}") } gbody = res.body slice1 = gbody.index("columns") slice2 = gbody.rindex("<center>") gbody = gbody.slice(slice1, (slice2-slice1+150)) return gbody end def getpages(htmlbody) pagebody = htmlbody.slice(htmlbody.index("<center>"),50) slice1 = pagebody.index("<b>") slice2 = pagebody.index("</b>") pages = pagebody.slice(slice1+3, (slice2-slice1-3)) pages = Integer(pages) return pages end alphabet = %w(a b c d e f g h i j k l m n o p q r s t u v w x y z *) alphacounter = 0; allwords = Array.new out = File.new('wordlist.html', 'w') out.puts "<html>" while alphacounter < alphabet.length counter = 1 cycles = 1 while counter <= cycles body = getbody(alphabet[alphacounter],(counter)) if counter == 1 if alphabet[alphacounter] == "s" cycles = 1010 else cycles = getpages(body) end puts "cycles: #{cycles}" end counter += 1 wordbody = body.slice(0,body.index("</table>")) peices = Array.new innercounter = 0; while (wordbody.include? "<a href") slice1 = wordbody.index("<a href") slice2 = wordbody.index("</a>") peices[innercounter] = wordbody.slice(slice1,(slice2-slice1+4)) innercounter += 1 wordbody = wordbody.slice((slice2+4),wordbody.length) end peices.compact! i = 0 while i < peices.length peices[i].insert((peices[i].index("=")+2),"http://www.somesite.com") i += 1 end peices.each do |item| out.puts "#{item} <br>" end puts "Letter: #{alphabet[alphacounter]} page: #{counter} total pages: #{cycles}" end alphacounter += 1 end out.puts "</html>"</pre> <a href="http://www.refactormycode.com/codes/306-can-this-scraper-be-simplified" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>