Skip to content

Instantly share code, notes, and snippets.

@titouanc
Created January 13, 2012 09:46
Show Gist options
  • Save titouanc/1605327 to your computer and use it in GitHub Desktop.
Save titouanc/1605327 to your computer and use it in GitHub Desktop.
=begin
Si vous avez un Mac, copiez tout ce code à partir de "require 'net/http'" (en gardant une ligne vide à la fin),
ouvrez l'application terminal (Applications > Utilitaires > Terminal), et tapez la commande suivante:
cat | ruby
collez le code, et ensuite tapez CTRL+D
Vous permettrez aux restos du coeur d'avoir leurs 40 tonnes de légumes plus facilement
=end
require 'net/http'
url = URI.parse "http://www.planetevegetal.com/RC/"
100.times do |i|
Net::HTTP.start url.host, url.port do |http|
page = http.get url.path
cookie = page.to_hash['set-cookie'][0].gsub(/.*(PHPSESSID=[\dA-Z]+;).*/m, '\1')
res = 0
page.body.gsub /<label for=\"captchaResult\">.+<b>(\d+)\s*([+x-])\s*(\d+)<\/b>/ do |match|
o1 = $1.to_i
o2 = $3.to_i
if $2 == '+'
res = o1+o2
elsif $2 == '-'
res = o1-o2
elsif $2 == 'x'
res = o1*o2
else
raise "Operation inconnue (#{$2})"
end
end
page = http.post "/RC/index.php", "captchaResult=#{res}", {"Cookie" => cookie}
puts "Post: #{$1} #{$2} #{$3} = #{res} :: #{page.code} #{page.to_hash['location']}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment