mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Update Foreign Affairs
This commit is contained in:
parent
ce902f5dbd
commit
88519f5a44
@ -3,7 +3,7 @@ import re
|
|||||||
|
|
||||||
|
|
||||||
def select_form(form):
|
def select_form(form):
|
||||||
return form.attrs.get('class', None) == 'user-login-form'
|
return form.attrs.get('id', None) == 'user-login'
|
||||||
|
|
||||||
|
|
||||||
class ForeignAffairsRecipe(BasicNewsRecipe):
|
class ForeignAffairsRecipe(BasicNewsRecipe):
|
||||||
@ -110,9 +110,16 @@ class ForeignAffairsRecipe(BasicNewsRecipe):
|
|||||||
return soup
|
return soup
|
||||||
|
|
||||||
def get_browser(self):
|
def get_browser(self):
|
||||||
|
import html5lib
|
||||||
|
from lxml import html
|
||||||
br = BasicNewsRecipe.get_browser(self)
|
br = BasicNewsRecipe.get_browser(self)
|
||||||
if self.username is not None and self.password is not None:
|
if self.username is not None and self.password is not None:
|
||||||
br.open('https://www.foreignaffairs.com/user?destination=user%3Fop%3Dlo')
|
# mechanize fails to parse the html correctly, so use html5lib to
|
||||||
|
# sanitize the html first
|
||||||
|
response = br.open('https://www.foreignaffairs.com/user?destination=user%3Fop%3Dlo')
|
||||||
|
root = html5lib.parse(response.get_data(), treebuilder='lxml', namespaceHTMLElements=False)
|
||||||
|
response.set_data(html.tostring(root))
|
||||||
|
br.set_response(response)
|
||||||
br.select_form(predicate=select_form)
|
br.select_form(predicate=select_form)
|
||||||
br.form['name'] = self.username
|
br.form['name'] = self.username
|
||||||
br.form['pass'] = self.password
|
br.form['pass'] = self.password
|
||||||
|
Loading…
x
Reference in New Issue
Block a user