0
我想從使用機械化的網站返回電子郵件地址。通過使用下面的代碼,我很容易確定是否在頁面上找到了「@」符號。使用機械化提取電子郵件地址
但是,我想返回@符號周圍的字符以確定它是否可能是電子郵件地址。任何人都知道,一旦找到了@我可能會返回周圍的角色?
我知道機械化可以返回鏈接,但電子郵件地址可能不是鏈接。謝謝!
require 'mechanize'
mechanize = Mechanize.new { |agent|
agent.open_timeout = 4
agent.read_timeout = 4
agent.max_history = 0
agent.follow_meta_refresh = true
agent.keep_alive = false
}
website = ARGV[0]
keyword = "@"
page = mechanize.get(website)
if page.body.include?(keyword)
puts "found \"#{keyword}\" on #{website}"
else
puts "not found"
end
你需要使用正則表達式:'電子郵件= page.body [正則表達式]' – pguardiario 2014-09-02 03:03:44