Python Mechanize: submit button will not work no attribute 'click' -


there form on webpage: https://www.avanza.se/mina-sidor/kontooversikt.html

i trying fill in , submit using this:

# -*- coding: utf-8 -*- import cookielib  import urllib2  import mechanize  bs4 import beautifulsoup lxml import html  import urllib2, base64, lxml import numpy np import unicodedata import datetime import re import time  url = "https://www.avanza.se/mina-sidor/kontooversikt.html"  br = mechanize.browser()   cookiejar = cookielib.lwpcookiejar()  br.set_cookiejar( cookiejar )   # browser options br.set_handle_equiv(true) br.set_handle_gzip(true) br.set_handle_redirect(true) br.set_handle_referer(true) br.set_handle_robots(false)  # follows refresh 0 not hangs on refresh > 0 br.set_handle_refresh(mechanize._http.httprefreshprocessor(), max_time=1)  br.addheaders = [('user-agent', 'mozilla/5.0 (x11; u; linux i686; en-us; rv:1.9.0.1) gecko/2008071615  fedora/3.0.1-1.fc9 firefox/3.0.1')]  br.open(url)  f in br.forms():     if f.attrs['class'] == 'loginform clearfix':         br.f = f     print f         break  br.f[ "j_username" ] = "user" br.f[ "j_password" ] = "pass"  res = br.submit()   time.sleep(5)  br.open('https://www.avanza.se/handla/aktier.html/kop/5447/abb-ltd')  #getting response in beautifulsoup soup = beautifulsoup(br.response().read(), 'lxml') print(soup.prettify().encode("utf-8")) 

and print verifies correct form:

<div class="section accordion-togglebar">   <a class="togglebar whitebg normalblack notopborder ubuntu active" href="#" data-login-method="usercredentials">     <img src="/jmvc/avanzabank/images/inloggningsuppgifter_ic.svg" class="logintypeicon" alt="inloggningsuppgifter" title="inloggningsuppgifter">     användarnamn &amp; lösenord <span class="arrow fright"></span>   </a>   <div class="togglebarcontent nopaddingtop ">     <div class="messagewrapper formlogin"></div>     <form autocomplete="off" class="loginform clearfix" method="post" action="/ab/noop">       <input placeholder="användarnamn" type="text" name="j_username" autocapitalize="none">       <input placeholder="lösenord" type="password" name="j_password">       <button class="focusbtn loginbutton margintop5px marginbottom15px errortooltipplacement fright" type="submit" disabled="disabled">logga in</button>        <a class="margintop4px defaultsize plclink" href="/glomt-uppgift.html">glömt lösenord eller användarnamn?</a>     </form>   </div> </div> 

however when try submit get:

traceback (most recent call last):   file "scrap_mec.py", line 91, in <module>     res = br.submit()    file "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 541, in submit     return self.open(self.click(*args, **kwds))   file "/usr/lib/python2.7/dist-packages/mechanize/_mechanize.py", line 530, in click     request = self.form.click(*args, **kwds) attributeerror: 'nonetype' object has no attribute 'click' 

i think still have use select_form method browser knows form you're trying submit


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -