require 'open-uri'
require 'nokogiri'
def scrape(url)
html = open(url).read
nokogiri_doc = Nokogiri::HTML(html)
final_array = []
nokogiri_doc.search("a").each do |element|
element = element.text
final_array << element
end
final_array.each_with_index do |index|
puts "#{index}"
end
end
scrape('http://www.infranetsol.com/')
In this I'm only getting the a tag but I need the email id and phone number into an excel file.
All you have is text. So, what you can do, is to only keep string tha look like email or phone number.
Fo instance, if you keep your result in an array
You can get element with an email (string with a '@') :
You can get element with a phone number (string with at least 5 digits) :
The whole code :