Forum: Ruby ruby (mechanize , net/http)

Posted by Vlad Smith (neverhood)
on 2009-06-30 19:39
Hi guys.
 I`m using mechanize to get some images from the web application. I have
2 problems:
 1-st : I can`t catch the links. The whole link looks like <a href =
"https://.../reports/switch_accounts.html?..."See full report</a>

And there`re couple of these that i try to catch with a singe regexp

i tried this :
<code>
final.links_with(:href => %r{/switch_accounts.html/} ).each do |link|
puts link.href, link.text
end
</code>

but it doesn`t display anything, but i`m pretty much sure there`re those
links in the 'final' webpage

The second problem - how can i actually save the images to a selected
folder(assuming i have the links for them)?

Thatnks everybody, any ideas are really appreciated
Posted by Rüdiger Brahns (Guest)
on 2009-07-03 10:36
(Received via mailing list)
Hello

If you didn't find it yet:

 >> str1 = 'http://...reports/switch_accounts.html?..'
=> "http://...reports/switch_accounts.html?.."
 >> re1 = %r{/switch_accounts.html/}
=> /\/switch_accounts.html\//
 >> str1.match re1
=> nil
 >> str2 = 'http://...reports/switch_accounts.html/?..'
=> "http://...reports/switch_accounts.html/?.."
 >> str2.match re1
=> #<MatchData:0xb7e1695c>
 >> re2 = %r{/switch_accounts.html\?}
=> /\/switch_accounts.html\?/
 >> str1.match re2
=> #<MatchData:0xb7e0c8d0>

I don't know mechanize, but str2 is an url your regex (re1) would match.
re2 is the regex that matches your sample url.

Regards, R.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.