extract.rb
# Return all the books found in the HTML of the given Nokogiri node
Return all the books found in the HTML of the given Nokogiri node
Return all the books found in the HTML of the given Nokogiri node
def extract_books(doc)
  book_nodes = doc.css('#kp-notebook-library .kp-notebook-library-each-book')
  book_nodes.map do |node|
    title_node = node.css('h2').first
    title = title_node.text
    asin_json = node.css('[data-get-annotations-for-asin]').first.attr('data-get-annotations-for-asin')
    asin = JSON.parse(asin_json)['asin']
    author_node = title_node.next
    author = author_node.text.sub(/^By: /, '')
    {
      title: title,
      author: author,
      asin: asin
    }
  end
end
def extract_books ( doc ) book_nodes = doc . css ( '#kp-notebook-library .kp-notebook-library-each-book' ) book_nodes . map do | node | title_node = node . css ( 'h2' ) . first title = title_node . text asin_json = node . css ( '[data-get-annotations-for-asin]' ) . first . attr ( 'data-get-annotations-for-asin' ) asin = JSON . parse ( asin_json ) [ 'asin' ] author_node = title_node . next author = author_node . text . sub ( / ^By:  / , '' ) { title : title , author : author , asin : asin } end end
Return all the books found in the HTML of the given Nokogiri node
Return all the books found in the HTML of the given Nokogiri node
doc
<not_specific>