lib/blackbook/importer/aol.rb in blackbook-1.0.3 vs lib/blackbook/importer/aol.rb in blackbook-1.0.4

- old
+ new

@@ -53,20 +53,25 @@ def scrape_contacts unless auth_cookie = agent.cookies.find{|c| c.name =~ /^Auth/} raise( Blackbook::BadCredentialsError, "Must be authenticated to access contacts." ) end - # Get user id from cookies - user_id = auth_cookie.value.scan(/&uid:([^&]+)&/).first.first - - # Get contacts print page - contacts_uri = agent.current_page.body.scan(/document.forms.searchForm.action = \"(.+)\";/) - raise( Blackbook::BadCredentialsError, "Must be authenticated to access contacts." ) unless contacts_uri - page = agent.get contacts_uri.first.first + # jump through the hoops of formulating a request to get printable contacts + uri = agent.current_page.uri.dup + inputs = agent.current_page.search("//input") + user = inputs.detect{|i| i['type'] == 'hidden' && i['name'] == 'user'} + utoken = user['value'] + path = uri.path.split('/') + path.pop + path << 'addresslist-print.aspx' + uri.path = path.join('/') + uri.query = "command=all&sort=FirstLastNick&sortDir=Ascending&nameFormat=FirstLastNick&user=#{utoken}" + page = agent.get uri.to_s + # Grab all the contacts - names = page.search("//a[@class='contactNameLabel']").map{|a| a.innerText}.flatten - emails = page.body.scan( /<span class="contactOtherEmailLabel">([^<]+)<\/span>/ ).flatten + names = page.body.scan( /<span class="fullName">([^<]+)<\/span>/ ).flatten + emails = page.body.scan( /<span>Email 1:<\/span> <span>([^<]+)<\/span>/ ).flatten (0...[names.size,emails.size].max).collect do |i| { :name => names[i], :email => emails[i] }