开发者

Login to site programatically using python

开发者 https://www.devze.com 2023-04-10 18:47 出处:网络
I am wondering on how to log in to specific site, however no luck so far. The way it happens on browser is that you click on button, it triggers jQuery AJAX request to /ajax/authorize_ajax.html with

I am wondering on how to log in to specific site, however no luck so far.

The way it happens on browser is that you click on button, it triggers jQuery AJAX request to /ajax/authorize_ajax.html with post variables login and pass. When it returns result = true it reloads document and you are logged in.

When I go to /ajax/authorize_ajax.html on my browser it gives me {"data": [{"result":false}]} in response. Using C# I did went to this address and posted login and pass and it gave me {"data": [开发者_JS百科{"result":true}]} in response. However then, of course, when I go back to main folder of the website I'm not logged in.

Can anyone help me solve this problem? I think that cookies are set via javascript, is it even possible in that case? I did some research and all I could do is this, please help me to get around with this problem. Used urllib in python and web libraries in .NET.

EDIT 0

It is setting cookie in response headers. SID, PATH & DOMAIN. Example: sid=bf32b9ff0dfd24059665bf1d767ad401; path=/; domain=site

I don't know how to save this cookie and go back to / using this cookie. I've never done anything like this before, can someone give me some example using python?

EDIT 1

All done, thanks to this post - How to use Python to login to a webpage and retrieve cookies for later usage?


Here's a blog post I did a while ago about using an HttpWebRequest to post to a site when cookies are involved:

http://crazorsharp.blogspot.com/2009/06/c-html-screen-scraping-part-2.html

The idea is, when you get a Response using the HttpWebRequest, you can get access to the Cookies that are sent down. For every subsequent request, you can new up a CookieContainer on the request object, and add the cookies that you got into that container.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号