使用 Ruby 学习抓取。我正在尝试计算给定页面的出站链接数量,但我不确定如何告诉 Ruby 我只想计算出站链接。
我当前的代码:
require "open-uri"
# Collect info
puts "What is your URL?"
url = gets.chomp
puts "Your URL is #{url}"
puts "Loading..."
# Check keyword count
page = open(url).read
link_total = page.scan("</a>")
# obl_count = ???
link_count = link_total.count
puts "Your site has a total of #{link_count} links."
我怎样才能完成这个?