Nokogiri parsing Google page. Want links
Ruby friends,
I do a Google search on. for instance,
“Bob Golba” “(970) 581-8551”
I then Firefox inspect the result and see the first result as
<a href=“http://www.lbaronline.com/rosters/showAgent.asp?id=5281” onmousedown="return rwt
(this,'','','','1','AOvVaw3V3rJ0Lm_aRJ7Vp4EavfPN','','0ahUKEwivv_er0JnYAhVH12MKHfIpB6IQFggpMAA','','',event)">
Golba, Bob golba.bob@gmail.com - Loveland Berthoud Association of …
I wish to pick up the string
"http://www.lbaronline.com/rosters/showAgent.asp?id=5281"
The test program I am using is:
require ‘open-uri’
require ‘nokogiri’
require ‘byebug’
html_data = open(“https://www.google.com/search?&q=“Bob+Golba”+"(970)+581-8551"”).read
nokogiri_object = Nokogiri::HTML(html_data)
elements = nokogiri_object.xpath(’//h3/a’)
byebug
xyz=123
when I do a
elements[0]
at the byebug I get
#<Nokogiri::XML::Element:0x2af427b2e0f8 name=“a” attributes=[#<Nokogiri::XML::Attr:0x2af427b2efd0 name=“href” value="/url?q=http://www.lbaronline.com/rosters/showAgent.asp%3Fid%3D5281&sa=U&ved=0ahUKEwiChu-a05nYAhVR8mMKHTW_CaQQFggUMAA&usg=AOvVaw1sF6uZXxfSqYfqythiWpjj">] children=[#<Nokogiri::XML::Text:0x2af427b29b20 "Golba, “>, #<Nokogiri::XML::Element:0x2af427b29a58 name=“b” children=[#<Nokogiri::XML::Text:0x2af427b29850 “Bob golba”>]>, #<Nokogiri::XML::Text:0x2af427b296ac ".bob@gmail.com - Loveland Berthoud Association …”>]>
I have tried many things and the closest I have come is to get
(byebug) nokogiri_object.xpath(’//h3/a’)[0].values
["/url?q=http://www.lbaronline.com/rosters/showAgent.asp%3Fid%3D5281&sa=U&ved=0ahUKEwj389zjsJnYAhVRImMKHVrSDKYQFggUMAA&usg=AOvVaw3LKL9gpeGOlDLLysgxrTQw"]
How do I pick up the object of the href? That is how do I get the actual string
“http://www.lbaronline.com/rosters/showAgent.asp?id=5281”
?
Ralph Shnelvar