1

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": [{"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?

Community
  • 1
  • 1
Stan
  • 25,744
  • 53
  • 164
  • 242
  • Like utdemir said, take a look at Selenium, particularly their javascript-enabled headless browser. – prestomanifesto Oct 05 '11 at 21:26
  • Take look the repsonse you are getting in c# and see if there is are any additional http headers being sent back. You are just looking at the Json retuned in the body, and there may be some additional clues in the headers – user957902 Oct 05 '11 at 21:27

1 Answers1

1

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.

BFree
  • 102,548
  • 21
  • 159
  • 201