0

I'm trying to login to a site using the requests library in Python.

In the returned html, I see "You must have javascript enabled to login". So, I test it in my browser with javascript disabled, and it says the same thing.

My question is, is there a library in Python that will allow me to login to a site while maintaining the session, that also supports javascript?

user3412816
  • 53
  • 1
  • 8
  • have you looked into mechanize ? – karthikr Mar 13 '14 at 01:05
  • requests is a python lib to make sessions and http requests. see this answer [http://stackoverflow.com/questions/18678066/consecutive-requests-with-python-requests-session-not-working](http://stackoverflow.com/questions/18678066/consecutive-requests-with-python-requests-session-not-working). also you taggued your question with javascript. does your question have something to do with javascript? – Lynch Mar 13 '14 at 01:07
  • have you actually tried to log in via your python library? You will always see that message in the source code, it's just a browser with javascript enabled won't show it to the user. – Red Alert Mar 13 '14 at 01:07
  • @Red, yes I did, I got the response that I need javascript, karthikr I'm looking at that right now lynch, I'll remove that tag – user3412816 Mar 13 '14 at 01:11
  • @karthikr, I've just tried logging in with mechanize, but it gives me the same message. What do you think about Selenium? – user3412816 Mar 13 '14 at 01:23

1 Answers1

1

In the html, we use <noscript> tag to detect if the javascript is enabled.

<noscript>
    <div class="noscript">
        You must have javascript enabled to login
    </div>
</noscript>

Now most of websites use ajax to communicate with server asynchronously. So it need the javascript enabled. In python you can use ghost.py, selenium capserjs, phantomjs, pyv8.

Also, you can capture the package use chrome web develepe tools . Then you can know what requests are send to the server. And you simulate the requests use python requests to get the expected response.

atupal
  • 16,404
  • 5
  • 31
  • 42