我目前有一个程序使用net \ http库来检索页面源,直到找到与用户给出的字符串匹配的标题。代码可以工作,但是在循环访问多个页面以查找标题时,它确实很慢。有没有办法只检索标题而不是整个代码页?
这就是代码的样子:
require 'net\http'
class Card
attr_accessor :name
#attr_reader :s, :go, :here
def getEm
@i = 1
@card = Net::HTTP.get(URI("http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=#{@i}"))
while true
@card =~ /(#{self.name})/i ? break : @i = @i + 1
@card = Net::HTTP.get(URI("http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=#{@i}"))
end
puts @i
puts @card.match(/(#{self.name})/i)
end
end
$cardname = "Basalt Monolith"
c = Card.new
c.name = ARGV[0] || $cardname
c.getEm