Last active
April 28, 2016 12:33
-
-
Save yuchan/b84796ce71085abd4e3eeeae3287b67d to your computer and use it in GitHub Desktop.
This file contains 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
# coding: utf-8 | |
# before execute this script, please install mechanize. | |
# [sudo] gem install mechanize --no-document | |
# and run! | |
# ruby url_encoded_list.rb | |
require 'mechanize' | |
require 'cgi' | |
require 'pp' | |
agent = Mechanize.new | |
agent.user_agent_alias = 'Mac Safari' | |
page = agent.get "http://www.w3schools.com/tags/ref_urlencode.asp" | |
table = page.css('.w3-table-all').first | |
trs = table.search('tr') | |
chars = [] | |
deadchars = [] | |
trs.each do |tr| | |
tds = tr.search('td') | |
tds.each do |td| | |
chars.push td.text | |
encoded = CGI.escape(td.text) | |
doubleDecoded = CGI::unescape(CGI::unescape(encoded)) | |
if td.text != doubleDecoded | |
deadchars.push td.text | |
end | |
break | |
end | |
end | |
pp "all chars: " + chars.to_s | |
pp "broken chars: " + deadchars.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment