Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am running an automated test script written in Ruby in which I get a result page, I would like to capture some of the text on the page and print them in a file. Can anyone assist with this effort?
Like the comments say, use Nokogiri.
Install it with gem install nokogiri.
To print the first top-level heading from example.com:
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open("http://www.example.com/"))
puts doc.css("h1").first
For more information on finding the text you want, try this guide
Related
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have simple HTML form, which I got from a web page:
<form id="my">
inputs....
</form>
I need to get this form via it's ID, which I know how to do:
#get_doc = Nokogiri::HTML(page)
nb = #get_doc.at_css('#my')
maybe could i iterate via object ?
I need to get all the input values and input names into some variable, and then pass it to URI.encode_www_form.
How can I do this? How could I get all the inputs inside the form with names and values, and pass them to encode_www_form?
arr = []
# form = doc.at_css '#form'
form.css('input').each do |i|
arr << [i['name'], i['value']]
end
URI.encode_www_form arr
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Here is ruby code:
[:val1, :val2, :val3].each do |method_name|
define_method(met_n) do |param1, param2|
inflect(param1, param2, SOME_CONST[met_n.to_s])
end
end
It's not mine code. I tried to figure out what inflect is, but I failed, although it should be a standard ruby function.
So how is it defined or where do I find a documentation about it?
inflect isn't a standard ruby function. This must be part of someone else's API.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
How can I load an OWL file in Gruff? It's not clear in the tutorials. I have a file, camera.owl. I need to display this in Gruff and view a graph of it.
I found the answer to this question myself. You need to look under the file menu. File > Load Triples > RDF/XML > File .... Thank you.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I'm working with Prawn gem and creating a table. I want to remove all its borders. I can't find this facility in the documentation.
How do I do that?
Here is the documentation for the prawn gem tables.
According to the "Constructor Details" section, you can pass a variety of :border_<x> options to the constructor... I'd suggest trying to pass a value of :border_width => 0 to your table constructor. (note: not tested - try it yourself and see what happens)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to download all the links in a webpage using a ruby script. My idea was to extract the href links if I could get the Source code, set a download location using command prompt. Is there a way for this ?
#!/usr/bin/env ruby
#
require "net/http"
require "uri"
#past your link
gets = STDIN.gets rescue nil
url = URI.parse gets
http = Net::HTTP.start(url.host, url.port) do |resp|
puts resp.get(url.request_uri).body
end
#your regular for href
or use http://nokogiri.org/