View Single Post
Old 06-02-2011, 05:13 PM   #5
bowbow
Member
bowbow began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jun 2011
Device: kindle 3
Hey,

thanks for your help. I studied all linked content and could advance a bit.

- Login is managed via cookies (JSESSIONID), so basically your linked solution should work

- I could build a recipe that should do it, yet I have one problem to solve (at least I guess), so here is the setup

Code:
import string, re
from calibre import strftime
from calibre.web.feeds.recipes import BasicNewsRecipe
from calibre.ebooks.BeautifulSoup import BeautifulSoup

class AdvancedUserRecipe1307036487(BasicNewsRecipe):
    title          = u'ChangeX Subscription'
    oldest_article = 7
    max_articles_per_feed = 100
    needs_subscription = True

    def get_browser(self):
        br = BasicNewsRecipe.get_browser()
        br.open('http://www.changex.de/')
        if self.username is not None and self.password is not None:
            br.open('http://www.changex.de/Login')
            br.select_form(name='login')
            br['nutzername']   = self.username
            br['passwort'] = self.password
            br.submit()
        return br

    feeds          = [(u'Arbeit und Leben', u'http://www.changex.de/Feed/ArbeitUndLeben/RSS20'), (u'Wirtschaft und Management', u'http://www.changex.de/Feed/WirtschaftUndManagement/RSS20'), (u'Wissen und Lernen', u'http://www.changex.de/Feed/WissenUndLernen/RSS20')]
The problematic section is
Code:
            br.select_form(name='login')
Because I get the error message
Code:
calibre, version 0.8.3
  File "/var/folders/fF/fFUreYAQGJWaokB+Pqrd+U+++TI/-Tmp-/calibre_0.8.3_tmp_doxSSg/calibre_0.8.3_xq8CvS_recipes/recipe0.py", line 20, in get_browser
    br.select_form(name='login')
  File "site-packages/mechanize/_mechanize.py", line 524, in select_form
mechanize._mechanize.FormNotFoundError: no form matching name 'login'
Problem might be, that the original login form on changex.de/login does not have a name. It is marked as follows:

Code:
<div class="leftside">
<h1>changeX Login (JavaScript-frei)</h1>
<form method="post" action="/Login">
<p>
<label for="nutzername">Nutzername:*</label>
<input id="nutzername" type="text" value="" name="username">
</p>
<p>
<label for="passwort">Passwort:*</label>
<input id="passwort" type="password" value="" name="password">
</p>
<p>
<button type="submit">
</p>
</form>
</div>
Unfortunately, I could not find out how mechanize can process that very form, so I am not sure whether my setup would work otherwise.

Do you know how to direct mechanize to a form without a name?
bowbow is offline   Reply With Quote