Class: Instascraper
- Inherits:
-
Object
- Object
- Instascraper
- Defined in:
- lib/instascraper.rb,
lib/instascraper/version.rb,
lib/instascraper/bookmark.rb
Defined Under Namespace
Classes: Bookmark
Constant Summary collapse
- VERSION =
"0.0.2"
Instance Method Summary collapse
- #bookmarks(folder = nil) ⇒ Object
-
#initialize(username, password = '') ⇒ Instascraper
constructor
A new instance of Instascraper.
Constructor Details
#initialize(username, password = '') ⇒ Instascraper
Returns a new instance of Instascraper.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/instascraper.rb', line 6 def initialize(username, password = '') @agent = Mechanize.new { |agent| agent.user_agent_alias = 'Mac Safari' } @agent.get('http://www.instapaper.com/user/login/') do |page| form = page.form form.texts.first.value = username form.password = password form.submit end end |
Instance Method Details
#bookmarks(folder = nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/instascraper.rb', line 17 def bookmarks(folder = nil) if folder home = @agent.get('http://www.instapaper.com/u/') path = home.link_with(:text => folder).href else path = '/u' end bookmarks = [] more_pages = true current_page = nil while more_pages do page = @agent.get("http://www.instapaper.com#{path}/#{current_page}") page.parser.css('.tableViewCell').each do |bookmark| bookmark.css('.tableViewCellTitleLink').first['href'] bookmarks << Bookmark.new(bookmark.css('.tableViewCellTitleLink').first['href'], bookmark.css('.tableViewCellTitleLink').first.text, 'http://www.instapaper.com'+bookmark.css('.textButton').first['href']) end if page.link_with :text => /Older items/ current_page = (current_page ? current_page + 1 : 1 ) else more_pages = false end end return bookmarks end |