mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-08 18:54:09 -04:00
Failed attempt at getting SCMP to serve full content after login
This commit is contained in:
parent
575a6ea121
commit
0b05e33224
@ -2,6 +2,8 @@
|
||||
scmp.com
|
||||
'''
|
||||
|
||||
from mechanize import Request
|
||||
import json
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
from calibre.ebooks.BeautifulSoup import Tag
|
||||
|
||||
@ -45,15 +47,33 @@ class SCMP(BasicNewsRecipe):
|
||||
|
||||
def get_browser(self):
|
||||
br = BasicNewsRecipe.get_browser(self)
|
||||
# br.set_debug_http(True)
|
||||
# br.set_debug_responses(True)
|
||||
# br.set_debug_redirects(True)
|
||||
if self.username is not None and self.password is not None:
|
||||
br.open('https://www.scmp.com/user/login')
|
||||
br.select_form(nr=0)
|
||||
br['name'] = self.username
|
||||
br['pass'] = self.password
|
||||
br.submit()
|
||||
# br.set_debug_http(True)
|
||||
# br.set_debug_responses(True)
|
||||
# br.set_debug_redirects(True)
|
||||
rq = Request('https://account.scmp.com/login', headers={
|
||||
'Accept': 'application/json, text/plain, */*',
|
||||
'Content-Type': 'application/json;charset=UTF-8',
|
||||
'Referer': 'https://account.scmp.com/login',
|
||||
}, data=json.dumps({'username': self.username, 'password': self.password}))
|
||||
self.log('Sending login request...')
|
||||
try:
|
||||
res = br.open(rq)
|
||||
except Exception as err:
|
||||
if hasattr(err, 'read'):
|
||||
raise Exception('Login request failed with error: {} and body: {}'.format(err, err.read().decode('utf-8', 'replace')))
|
||||
raise
|
||||
if res.code != 200:
|
||||
raise ValueError('Failed to login, check your username and password')
|
||||
nonce = json.loads(res.read())['nonce']
|
||||
rq = Request('https://www.scmp.com/centralize/signin?nonce=' + nonce, headers={
|
||||
'referer': 'https://account.scmp.com/login',
|
||||
'sec-fetch-mode': 'navigate',
|
||||
'sec-fetch-site': 'same-site',
|
||||
'sec-fetch-user': '?1'})
|
||||
res = br.open(rq)
|
||||
if res.code != 200:
|
||||
raise ValueError('Failed to login, check your username and password')
|
||||
return br
|
||||
|
||||
feeds = [
|
||||
|
Loading…
x
Reference in New Issue
Block a user