Created
May 6, 2013 17:31
-
-
Save bonau/5526628 to your computer and use it in GitHub Desktop.
rip for law contents
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
| source "https://rubygems.org" | |
| gem "mechanize" | |
| gem "redis" |
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
| # encoding: utf-8 | |
| require "rubygems" | |
| require "mechanize" | |
| require "redis" | |
| law_site = Mechanize.new { |agent| | |
| agent.user_agent_alias = "Mac Safari" | |
| } | |
| redis = Redis.new | |
| v_court_values = [] | |
| v_sys_values = [] | |
| law_site.get("http://jirs.judicial.gov.tw/FJUD/FJUDQRY01_1.aspx") do |page| | |
| page.form_with(name: "form1") do |form| | |
| form.field_with(name: "v_court").options.each do |option| | |
| v_court_values << option.value | |
| end | |
| form.radiobuttons_with(name: "v_sys").each do |radio| | |
| v_sys_values << radio.value | |
| end | |
| end | |
| end | |
| v_court_values.each do |v_court_value| | |
| v_sys_values.each do |v_sys_value| | |
| law_site.get("http://jirs.judicial.gov.tw/FJUD/FJUDQRY01_1.aspx") do |page| | |
| $stderr.puts "Processing #{v_court_value}-#{v_sys_value}..." | |
| $stderr.puts "Searching..." | |
| search_result = page.form_with(name: "form1") do |search| | |
| search.sdate = "19700101" | |
| search.edate = "99991231" | |
| search.radiobutton_with(name: "v_sys", value: v_sys_value).check | |
| search.field_with(name: "v_court").value = v_court_value | |
| search.field_with(name: "sel_judword").value = "常用字別" | |
| end.submit | |
| $stderr.puts "Search completed, parsing..." | |
| search_result.links.each do |link| | |
| redis.sadd "law_detail", link.href if link.href =~ /FJUDQRY03/ | |
| end | |
| next_page_link = search_result.link_with(text: "下一頁") | |
| begin | |
| $stderr.puts "Click next page." | |
| page = next_page_link.click rescue break | |
| page.links.each do |link| | |
| redis.sadd "law_detail", link.href if link.href =~ /FJUDQRY03/ | |
| end | |
| end while next_page_link = page.link_with(text: "下一頁") | |
| redis.hset "completed", "#{v_court_value}-#{v_sys_value}", true | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment