为什么不在控制台显示一组资源链接Ruby

Why not displayed in the console, a group of links to resources Ruby

为什么控制台不显示,一组资源链接Ruby

require 'open-uri'

url = 'http://www.google.com/search?q=ruby'

open(url) { |page| page_content = page.read()
links = page_content.scan(/<a class=1.*?href=\"(.*?)\"/).flatten
links.each { |link| puts link }
}

控制台输出空行

E:\work\storeapp3\app\storeapp\shop>ruby robota_z_fail.rb

我哪里错了?

你在正则表达式中有错别字:

#         ⇓
/<a class=1.*?href=\"(.*?)\"/

删除 1 并享受。