I am trying to parse results from duckduckgo search with Net::HTTP and store the links of the results of the array. However the result comes as a string. Any idea how get it any other type of data back as result or how to get the links from the string if there is no option to get the response in another type?
def getlinks(str, num_results)
uri = URI.parse("https://duckduckgo.com/?q=#{str}")
response = Net::HTTP.get_response(uri)
end
An example with Nokogiri :
require 'nokogiri'
page = Nokogiri::HTML(open("https://duckduckgo.com/?q=#{str}").read)
page.doc.css('a').first.attr(:href)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.