Turns out that the issue was that user_agent_alias
requires a specific type. All acceptable types are as follows:
- Linux Firefox (3.6.1)
- Linux Konqueror (3)
- Linux Mozilla
- Mac Firefox (3.6)
- Mac Mozilla
- Mac Safari (5)
- Mac Safari 4
- Mechanize (default)
- Windows IE 6
- Windows IE 7
- Windows IE 8
- Windows IE 9
- Windows Mozilla
- iPhone (3.0)
- iPad
- Android (Motorola Xoom)
Working code:
require 'rubygems'
require 'mechanize'
m = Mechanize.new
m.user_agent_alias = 'Mac Safari 4'
page = m.get("http://whatsmyuseragent.com/")
html = Nokogiri::HTML(page.body)
puts html.xpath('//*[(@id = "body_lbUserAgent")]').map(&:content)