Image

Авторизация на https + pycurl

вообщем после гугления и чтения многочисленных примеров было слепленно вот это




#!/usr/bin/python
#
# getbalance.py
#
# Copyright 2010 Dmitry Kalenchuk <koirn@koirn-debianbook>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.


import pynotify
import sys
import pycurl
import StringIO

def main():

if not pynotify.init("Basics"):
sys.exit(1)

c = pycurl.Curl()

c.setopt(pycurl.SSL_VERIFYPEER, 0)
c.setopt(pycurl.SSL_VERIFYHOST, 0)
c.setopt(pycurl.URL, "https://stat.byfly.by")
c.setopt (pycurl.HEADER, 1);
c.setopt (pycurl.USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
c.setopt (pycurl.FOLLOWLOCATION, 1);
c.setopt (pycurl.VERBOSE, 1);
c.setopt (pycurl.AUTOREFERER, 1);
c.setopt(pycurl.POSTFIELDS,"p_logname="mylogin"&p_pwd="my_pass"&p_lang=ru")
c.setopt(pycurl.POST,1)
b = StringIO.StringIO()
c.setopt(pycurl.WRITEFUNCTION, b.write)
c.perform()
n = pynotify.Notification("Summary", b.getvalue())
print b.getvalue()


if not n.show():
print "Failed to send notification"
sys.exit(1)

return 0

if __name__ == '__main__': main()


В ответ слышится "404 Not Found". Как я понял, после авторизации браузер перекидывает на страничку статистики, а со скриптом этого не происходит. Или же я не могу просто пройти авторизацию.