Answer the question
In order to leave comments, you need to log in
How to manage the data of a site that requires authorization without an API?
There is a site on which there is authorization, after which I see my information and regularly review it.
I want to write a script, if the site had an API - everything would be simple, but I can't understand why it doesn't work for me.
using this documentation apidock.com/ruby/Net/HTTP
Net::HTTP.start(uri.host, uri.port) do |http|
request1 = Net::HTTP::Post.new uri.request_uri
response = http.request request1 // тут я как бы отправлял серверу логин и пасс(урл на 100% верный и в ответе выдаёт тоже, что и браузере, что я успешно залогинен)
request2 = Net::HTTP::Get.new uri.request_uri
response = http.request request2 // а тут хотел бы видеть данные после авторизации, но я вижу только публичную информацию, как будто я вообще не логинился
end
Answer the question
In order to leave comments, you need to log in
I don’t program in ruby, but I dare to assume that
1) Cookies from the first response must be transferred to the second request
2) the server does not support a permanent connection - that is, it is necessary to spread it into different start / end blocks
on the stackoverflow, for example, they advise such a crutch for cookies
r = http.get(path)
cookie = {'Cookie'=>r.to_hash['set-cookie'].collect{|ea|ea[/^.*?;/]}.join}
r = http.get(next_path,cookie)
stackoverflow.com
It's only good practice to save cookies to a file and not log in all the time.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question