mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix Economist not working from France
This commit is contained in:
parent
0b0a8adedb
commit
1c2e89708f
@ -9,7 +9,7 @@ from calibre.web.feeds.news import BasicNewsRecipe
|
|||||||
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
|
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import re
|
import re, cookielib
|
||||||
|
|
||||||
class Economist(BasicNewsRecipe):
|
class Economist(BasicNewsRecipe):
|
||||||
|
|
||||||
@ -58,22 +58,20 @@ class Economist(BasicNewsRecipe):
|
|||||||
delay = 1
|
delay = 1
|
||||||
|
|
||||||
needs_subscription = False
|
needs_subscription = False
|
||||||
'''
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
if self.username and self.password:
|
# Add a cookie indicating we have accepted Economist's cookie
|
||||||
br.open('http://www.economist.com/user/login')
|
# policy (needed when running from some European countries)
|
||||||
br.select_form(nr=1)
|
ck = cookielib.Cookie(
|
||||||
br['name'] = self.username
|
version=0, name='notice_preferences', value='2:', port=None,
|
||||||
br['pass'] = self.password
|
port_specified=False, domain='.economist.com',
|
||||||
res = br.submit()
|
domain_specified=False, domain_initial_dot=True, path='/',
|
||||||
raw = res.read()
|
path_specified=False, secure=False, expires=None, discard=False,
|
||||||
if '>Log out<' not in raw:
|
comment=None, comment_url=None, rest={'HttpOnly': None},
|
||||||
raise ValueError('Failed to login to economist.com. '
|
rfc2109=False)
|
||||||
'Check your username and password.')
|
br.cookiejar.set_cookie(ck)
|
||||||
return br
|
return br
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
return self.economist_parse_index()
|
return self.economist_parse_index()
|
||||||
@ -105,7 +103,8 @@ class Economist(BasicNewsRecipe):
|
|||||||
a = node.find('a', href=True)
|
a = node.find('a', href=True)
|
||||||
if a is not None:
|
if a is not None:
|
||||||
url = a['href']
|
url = a['href']
|
||||||
if url.startswith('/'): url = 'http://www.economist.com'+url
|
if url.startswith('/'):
|
||||||
|
url = 'http://www.economist.com'+url
|
||||||
url += '/print'
|
url += '/print'
|
||||||
title = self.tag_to_string(a)
|
title = self.tag_to_string(a)
|
||||||
if title:
|
if title:
|
||||||
|
@ -9,7 +9,7 @@ from calibre.web.feeds.news import BasicNewsRecipe
|
|||||||
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
|
from calibre.ebooks.BeautifulSoup import Tag, NavigableString
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import re
|
import re, cookielib
|
||||||
|
|
||||||
class Economist(BasicNewsRecipe):
|
class Economist(BasicNewsRecipe):
|
||||||
|
|
||||||
@ -58,22 +58,19 @@ class Economist(BasicNewsRecipe):
|
|||||||
delay = 1
|
delay = 1
|
||||||
|
|
||||||
needs_subscription = False
|
needs_subscription = False
|
||||||
'''
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
if self.username and self.password:
|
# Add a cookie indicating we have accepted Economist's cookie
|
||||||
br.open('http://www.economist.com/user/login')
|
# policy (needed when running from some European countries)
|
||||||
br.select_form(nr=1)
|
ck = cookielib.Cookie(
|
||||||
br['name'] = self.username
|
version=0, name='notice_preferences', value='2:', port=None,
|
||||||
br['pass'] = self.password
|
port_specified=False, domain='.economist.com',
|
||||||
res = br.submit()
|
domain_specified=False, domain_initial_dot=True, path='/',
|
||||||
raw = res.read()
|
path_specified=False, secure=False, expires=None, discard=False,
|
||||||
if '>Log out<' not in raw:
|
comment=None, comment_url=None, rest={'HttpOnly': None},
|
||||||
raise ValueError('Failed to login to economist.com. '
|
rfc2109=False)
|
||||||
'Check your username and password.')
|
br.cookiejar.set_cookie(ck)
|
||||||
return br
|
return br
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
def parse_index(self):
|
def parse_index(self):
|
||||||
return self.economist_parse_index()
|
return self.economist_parse_index()
|
||||||
@ -105,7 +102,8 @@ class Economist(BasicNewsRecipe):
|
|||||||
a = node.find('a', href=True)
|
a = node.find('a', href=True)
|
||||||
if a is not None:
|
if a is not None:
|
||||||
url = a['href']
|
url = a['href']
|
||||||
if url.startswith('/'): url = 'http://www.economist.com'+url
|
if url.startswith('/'):
|
||||||
|
url = 'http://www.economist.com'+url
|
||||||
url += '/print'
|
url += '/print'
|
||||||
title = self.tag_to_string(a)
|
title = self.tag_to_string(a)
|
||||||
if title:
|
if title:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user