title: Watir with Ruby: undefined local variable or method `doc' for main:Object
body: <p>I was following <a href="https://www.google.com/url?sa=t&amp;rct=j&amp;q=&amp;esrc=s&amp;source=web&amp;cd=2&amp;cad=rja&amp;uact=8&amp;ved=0ahUKEwimlbK75YXLAhVIFj4KHQNGDkAQFggjMAE&amp;url=http%3A%2F%2Fwww.layeredthoughts.com%2Fautomation%2Fhow-to-write-your-first-ruby-web-bot-in-watir-scraping-weather-com&amp;usg=AFQjCNFME-reql2zO1Mx5F8nF6OzX31k-Q&amp;bvm=bv.114733917,d.cWw" rel="nofollow">this tutorial</a> for screen scraping with Ruby and Watir.</p>
  
  <p>I tried to write a simple script to return text from Wikipedia:</p>
  
  <pre><code>require "selenium-webdriver"
  browser = Selenium::WebDriver.for :chrome
  browser.get "https://wikipedia.org"
  require "nokogiri"
  puts doc.xpath(".//*[@id='langsearch-input']/p").inner_text
  </code></pre>
  
  <p>But when I run the script, I get this error in my terminal:</p>
  
  <pre><code>$ ruby app/views/layouts/scraper.rb
  app/views/layouts/scraper.rb:7:in `&lt;main&gt;': undefined local variable or method `doc' for main:Object (NameError)
  </code></pre>
  
  <p>I have nokogiri 1.6.7.2, watir-webdriver 0.9.1, and watir 4.0.2 installed.</p>
  
  <p>What am I doing wrong?</p>