Fix New Scientist login

This commit is contained in:
Kovid Goyal 2021-04-18 13:45:48 +05:30
parent 0f34f3c593
commit c1d261defb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -83,22 +83,19 @@ class NewScientist(BasicNewsRecipe):
ans = BasicNewsRecipe.get_article_url(self, article)
return ans.partition('?')[0]
def is_login_form(self, form):
return "action" in form.attrs and form.attrs['action'] == "/ns-login.php"
def get_browser(self):
br = BasicNewsRecipe.get_browser(self)
if self.username is not None and self.password is not None:
br.open('http://www.newscientist.com/')
try:
def is_login_form(form):
return "action" in form.attrs and form.attrs['action'] == "/login/"
br.open('https://www.newscientist.com/login/')
br.select_form(predicate=self.is_login_form)
br['log'] = self.username
br['pwd'] = self.password
br.submit()
except:
self.log.exception(
'Unable to locate login form! Switching to free mode.')
br.select_form(predicate=is_login_form)
br['email'] = self.username
br['password'] = self.password
res = br.submit().read()
if b'>Log out<' not in res:
raise ValueError('Failed to log in to New Scientist, check your username and password')
return br
feeds = [