Hey!
I have been going through some basic IO stuff and want to get into
something more “advanced”.
I would like to make a script who asks for a website and takes the
information (the text) on the website and put it into a textfile…
So now im wondering… how do I tell the script to download/read
text/content from a website… How do I do it? ( of course i do not want
anyone to actually write this script for me, i want to write it myself
but im a newbie and don’t know which libs and etc to read in)
Hey!
I have been going through some basic IO stuff and want to get into
something more “advanced”.
I would like to make a script who asks for a website and takes the
information (the text) on the website and put it into a textfile…
It means you wrote an input stream object into the file. Which seems
Weird. Wasn’t there anything in ‘file’ before this script started? You
set
it to append, so that might be a leftover from some other script you
wrote
that used that file. Delete it, or open the file with the ‘w’ flag
instead
of ‘a’, and run it again?
Also, you might want to avoid open(addr) {|addr| ... }, reusing the same
variable name. It's probably not the issue here, but shadowing variables
is inherently confusing. YMMV.
What VB’s CompareMode is, I have no idea. Case sensitivity? If so, I’d
personally manually use String#downcase in the conditional.
And, of course, there’s always regular expressions, the swiss army knife
of string searching, but those are for a longer discussion and you can
probably find material for those out there that explains them rather
nicely.
If InStr(1, Text1.Text, “String to find”, 1) > 0 Then Msgbox "I found
David V.
Ok!
But that doesn’t tell me the position of the string…
Say that you have a textfile with the sentence “Could you pass me the
milk please?” and I make a search for the string “milk”. Then I want to
know the position of where the search word starts so I can extract the
word into a variable… How do I do that?
Ok!
But that doesn’t tell me the position of the string…
Say that you have a textfile with the sentence “Could you pass me the
milk please?” and I make a search for the string “milk”. Then I want to
know the position of where the search word starts so I can extract the
word into a variable… How do I do that?
Use String#index, or String#=~. The former works with strings and
regular
expressions, the latter requires regular expressions, but I think it
also
saves the match data into the special global variable I don’t use or
remember the name of… Anyhoo:
For word extraction, I’m usually very, very bad doing those with
substring
indexes and abuse regexps wildly each and every time I need to get some
piece of text out of another one.
but im a newbie and don’t know which libs and etc to read in)
Thanks!
I’m a little late to this party, and it might be a little advanced
for you yet, but if you’re dealing with scripting against websites
you can do some pretty sick stuff using ‘mechanize’ (http:// mechanize.rubyforge.org/) and ‘hpricot’ (http:// code.whytheluckystiff.net/hpricot/).
Mechanize can click links and fill out forms. Hpricot can look for
text/tags in the resulting HTML. And Mechanize supports pluggable
parsers which lets you drop Hpricot right into Mechanize. It’s so
buttery…
-Mat
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.