Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from youpy/youpy
add script for "Under Translation of ECMA-262 3rd Edition"
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
%w/uri json nokogiri curb cgi/.each {|g| require g } | ||
|
||
root = 'http://www2u.biglobe.ne.jp/~oz-07ams/prog/ecma262r3/fulltoc.html' | ||
book = { | ||
:title => 'ECMA-262 3rd edition', | ||
:authors => [ | ||
'TAKI' | ||
], | ||
:cover_image => 'http://www.ecma-international.org/images/logo_printerf.jpg', | ||
:content_xpath => '//div[@class="section level1"]', | ||
:chapters => [] | ||
} | ||
|
||
def curl(url) | ||
c = Curl::Easy.new(url.to_s) | ||
c.follow_location = true | ||
c.perform | ||
c.body_str | ||
end | ||
|
||
doc = Nokogiri::HTML(curl(root)) | ||
doc.xpath('//body/dl/dt/a').each do |a| | ||
chapter_url = URI(root) + a[:href] | ||
chapter = { | ||
:uri => chapter_url, | ||
:title => a.text, | ||
} | ||
book[:chapters] << chapter | ||
end | ||
|
||
puts book.to_json |