Ruby: get address of the redirect when posting a page using Restclient
Hi I was wondering if this is possible, this is my scenario, I have a stand alone file that tries to get information from pages using RestClient and Nokogiri
I need to get the information of all t开发者_JAVA百科he videos available on a page "http://www.koldcast.tv/" so far I havent found a way to get these results on a HTML page (no flash) other than tricking the search page into returning the whole list back using 3 underscores as the search keywords, the problem is that the search is doing a post to a page which I assume is then redirecting to the final page and it gives you something like this "http://www.koldcast.tv/index.php/landingpage/search_results/921c6b6e491005d91d117b0fa88f31d1/" the problem there is that this url is only alive for 5 or 10 minutes so I cannot use this url everytime i need to run the stand alone file the search is in a form with a post to "http://www.koldcast.tv/index.php" which I imagine takes all the data from that form (there is some other hidden fields) and then redirects to that results page is there a way I can do the post with all the data and then get the page that is being redirected
I thank you for taking your time into helping, if I am not explaining myself complete I'll be happy to clear any doubts thanks a lot!
As that isn't a REST interface, RestClient may not be your best choice. You probably want something that more closely emulates a browser. For example, using mechanize:
require 'mechanize'
a = Mechanize.new
a.get('http://www.koldcast.tv') do |page|
search_result = page.form_with(:action =>"http://www.koldcast.tv/index.php") do |search|
search.keywords = "___"
end.submit
# Print all relative links (starting with "/")
search_result.links_with(:href => /^\//).each do |link|
puts link.href
end
end
This gets you partway there. You can see all the video links.
精彩评论