このコードを使用して、HTMLページの電子メールアドレスを一覧表示しています。電子メールの後に文字列内の文字を削除する方法
require 'nokogiri'
selector = "//a[starts-with(@href, \"mailto:\")]/@href"
doc = Nokogiri::HTML.parse File.read 'in.rb'
nodes = doc.xpath selector
addresses = nodes.collect {|n| n.value[7..-1]}
puts addresses
これは私が解析してるサンプルコードです:
<a href="mailto:[email protected]?subject=My Business Is Dying">
をしかし、私はちょうど電子メールアドレス以上のものを取得しています。私は私の結果でこれを得ています:
[email protected]?subject=My Business Is Dying
疑問符の後ろのすべてを削除するにはどうすれば電子メールアドレスですか?
'in.rb'はHTMLファイルですか? – tadman