Форум сайта python.su
4
Приветствую всех!
Порылся по форуму и не нашел. (на других не смотрел)
Суть вот в чем:
Вот эта конструкция(как по книге) работает
r = urllib.request.Request("https://docs.python.org/",headers=headers) u = urllib.request.urlopen(r) resp = u.read() print (resp)
r = urllib.request.Request("https://lk.megafon.ru/login/",headers=headers) u = urllib.request.urlopen(r) resp = u.read() print (resp)
import __hello__
Офлайн
16
Видимо число редиректов ограничено. Так как с мегафоном такая картина:
wget --no-check-certificate https://lk.megafon.ru/login/ --2016-10-25 02:57:02-- https://lk.megafon.ru/login/ Resolving lk.megafon.ru (lk.megafon.ru)... 85.26.148.161 Connecting to lk.megafon.ru (lk.megafon.ru)|85.26.148.161|:443... connected. WARNING: cannot verify lk.megafon.ru's certificate, issued by 'CN=thawte EV SSL CA - G3,O=thawte\\, Inc.,C=US': Unable to locally verify the issuer's authority. HTTP request sent, awaiting response... 302 Found Location: http://lk.megafon.ru:80/?noredirect [following] --2016-10-25 02:57:03-- http://lk.megafon.ru/?noredirect Connecting to lk.megafon.ru (lk.megafon.ru)|85.26.148.161|:80... connected. HTTP request sent, awaiting response... 302 Found Location: https://lk.megafon.ru:443/?noredirect= [following] --2016-10-25 02:57:03-- https://lk.megafon.ru/?noredirect= Connecting to lk.megafon.ru (lk.megafon.ru)|85.26.148.161|:443... connected. WARNING: cannot verify lk.megafon.ru's certificate, issued by 'CN=thawte EV SSL CA - G3,O=thawte\\, Inc.,C=US': Unable to locally verify the issuer's authority. HTTP request sent, awaiting response... 302 Found Location: http://lk.megafon.ru:80/?noredirect= [following] --2016-10-25 02:57:03-- http://lk.megafon.ru/?noredirect= Connecting to lk.megafon.ru (lk.megafon.ru)|85.26.148.161|:80... connected. HTTP request sent, awaiting response... 302 Found Location: https://lk.megafon.ru:443/?noredirect= [following] --2016-10-25 02:57:03-- https://lk.megafon.ru/?noredirect= Connecting to lk.megafon.ru (lk.megafon.ru)|85.26.148.161|:443... connected. WARNING: cannot verify lk.megafon.ru's certificate, issued by 'CN=thawte EV SSL CA - G3,O=thawte\\, Inc.,C=US': Unable to locally verify the issuer's authority. HTTP request sent, awaiting response... 302 Found Location: https://lk.megafon.ru:443/login [following] --2016-10-25 02:57:04-- https://lk.megafon.ru/login Reusing existing connection to lk.megafon.ru:443. HTTP request sent, awaiting response... 302 Found Location: /login/ [following] --2016-10-25 02:57:04-- https://lk.megafon.ru/login/ Reusing existing connection to lk.megafon.ru:443. HTTP request sent, awaiting response... 200 OK Length: 19439 (19K) [text/html] Saving to: 'index.html.2'
Офлайн
4
VadimKДва месяца назад вот этот код прекрасно работал
Видимо число редиректов ограничено.
url = 'https://lk.megafon.ru/login/' r=requests.get(url, auth=HTTPDigestAuth('login', 'pass')) txt = r.text soup = BeautifulSoup(txt) word = soup.findAll('div','gadget-remainders-td gadget-remainders-td-3 gadget-remainders-summ gadget-remainders-mobile') word = str(word) test = re.sub('\<[^>]*\>', '', word) result = re.sub(r'Остаток / Общий объём', '', test) result = re.sub(r'/', 'из', result) print (result)
url = 'https://lk.megafon.ru/remainders/' cookie = {'csrfId': 'd495a08ad-da48-409b-ac21-5cbffc699e3e'} r = requests.post(url, cookies=cookie) r = requests.get(url,timeout=5) if r.status_code == 200: for cookie in r.cookies: print(cookie)
<form action="/dologin/" class="form form-login-autofill" method="POST"> <input type="hidden" name="CSRF" value="lz9t6Wk4WPpb3k2IEiAUyоlrE3WPHOGGWkf13u8I3yPF9QCmQPoKZk2x1U0zQW8pSyghPkrOk/2vEN8X4UC5jH8seHlTNKy9lN+yv78FUUE="/>
import __hello__
Офлайн
16
В смысле победить ? Придется спарсить CSRF и так же его подсунуть.
Офлайн
3
Скорее пересмотреть надо код и сайт, они явно поменяли сайт, например убрали возможность отправки смс с сайта (гады)…
ЗЫ. забудь фразу “Два месяца назад вот этот код прекрасно работал” На “той стороне” тоже постоянно иммитация бурной деятельности и всегда какието перемены… Если тебе API не предоставили, будь готов менять прогу хоть каждый день…
Офлайн