I have the following Ruby code:
require 'rubygems'
require 'rest_client'
url = 'http://asdf.com'
response = RestClient.get(url)
b = response.body
result = b.match(/<head>(.*)<\/head>/)[1]
puts result
when I try to parse this page to get the header I get the following error:
7:in `<main>': undefined method `[]' for nil:NilClass (NoMethodError)
What am I doing wrong?(apart from using regex to parse html. I’m just experimenting)
At a guess the
<head>tag isn’t all on one line. Try:(Note the
m, switching you to multiline mode).