Deleted unwanted characters from a string

Hi :slight_smile:

Im trying to write a script that can check if Rapidshare links are
online, ive managed to get the content of [code] tags from my website
using scrubyt

<root> <link>http://rapidshare.com/files/example/example.rar</link>

Im trying to strip the string of anything but the
“http://rapidshare.com/files/example/example.rar” part, so I can work
with it.

I tried to use the .delete function however it doesn’t work.

[code]require ‘rubygems’
require ‘scrubyt’

data = Scrubyt::Extractor.define do
fetch ‘mywebsite.com is available for purchase - Sedo.com’
fill_textfield ‘user’, ‘myusername’
fill_textfield ‘passwrd’, ‘mypassword’
submit
fetch ‘http://mywebsite/index.php?topic=672’
link ‘//div/code’
end

rapidshare = data.to_xml.write($stdout, 1)
rapidshare.to_s
rapidshare.delete “”
print rapidshare
[/code]

Any help would be great appreciated :slight_smile:

is my full code

Juo H. [email protected] wrote:

rapidshare.delete “”

You are throwing away the new version of the string. Capture it, like
this:

rapidshare = rapidshare.delete(whatever)

Hey, I tried that

rapidshare = data.to_xml.write($stdout, 1)
rapidshare.to_s
rapidshare = rapidshare.delete(<"link">)
print rapidshare

is now at the end of my code, however I still get the error
“NoMethodError: undefined method ‘delete’ for 139:Fixnum”

wow, thanks for such a comprehensive reply, and working code. You’re a
true gentleman :slight_smile:
Thanks! :smiley:

On Thu, Jun 18, 2009 at 6:58 AM, Juo H.[email protected] wrote:

Hey, I tried that

[code]
rapidshare = data.to_xml.write($stdout, 1)

This is setting rapidshare to whatever the String#write method which
is an extension to the String class provided by scrubyt.

It looks like it actually returns the number of characters written,
let’s say for arguments sake that you write 42 characters, the
actually value doesn’t matter since:

rapidshare.to_s
This evaluates to “42” or whatever the string representation of the
return value from String#write was, and then does noting with the
result.

Maybe something like:

rapidshare = data.to_xml
rapidshare.write($stdout, 1)

which would make rapidshare reference the result of data.to_xml (which
I’m assuming here is a string.

Now to the real meat,

rapidshare = rapidshare.delete(<“link”>)

As Inigo Montoya would say, “I don’t think that method means what you
think it means.”

irb(main):001:0> “if l < k and k < j then j > l”.delete(“”)
=> "f ad j the j "

String#delete removes ANY characters which are in the argument from
the receiver.

If you are sure that the string in rapidshare is well formed then you
could use something like

print rapidshare.gsub(%r{</?link>}, “”)
or
rapidshare = rapidshare.gsub(%r{</?link>}, “”)
print rapidshare

Putting it all together

require ‘rubygems’
require ‘scrubyt’

data = Scrubyt::Extractor.define do
fetch ‘mywebsite.com is available for purchase - Sedo.com’
fill_textfield ‘user’, ‘myusername’
fill_textfield ‘passwrd’, ‘mypassword’
submit
fetch ‘http://mywebsite/index.php?topic=672’
link ‘//div/code’
end

rapidshare = data.to_xml
rapidshare.write($stdout, 1)
print rapidshare.gsub(%r{</?link>}, “”)

–
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Twitter: http://twitter.com/RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale