how to remove AttributeError in Robobrowser

╄→尐↘猪︶ㄣ 提交于 2019-12-11 07:14:00

问题


i'm trying to login to my college id and fetch some info using robobrowser. bu i'm getting this traceback when i try to print contents of my dashboard.

Traceback (most recent call last):
  File "C:/Users/User/PycharmProjects/dictionary/RobobrowseErp.py", line 26, 
in <module>
    print(open.parsed)
AttributeError: 'NoneType' object has no attribute 'parsed'

here is my code.

from robobrowser import RoboBrowser
import requests

start = requests.session()

token = 'value_of_token'
token_1 = 'value_of_token_1 '

stuff = {

   '__VIEWSTATEGENERATOR': token,
   'btnLogIn': 'Login',
   '__VIEWSTATE': token_1,
   'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, 
like Gecko) Chrome/23.0.1271.64 Safari/537.11'
}

start.headers = stuff


browser = RoboBrowser(parser='lxml', session=start)
browser.open('http://erp.college_name.edu/')
sign_in = browser.get_form(id='some_value')
sign_in['tbUserName'].value = 'myId'
sign_in['tbPassword'].value = 'myPass'
open = browser.submit_form(sign_in)
print(open.parsed)

here is the source code.

 <form name="form1" method="post" action="Welcome_iie.aspx" id="some_value" class="bgLogin">  <div class="formWrap">
                    <div class="error"> <span id="lblDispMessage"></span></div>
                        <div class="group">
                            <input name="tbUserName" type="text" id="tbUserName"><span class="highlight"></span><span class="bar"></span>
                            <label>Username</label>
                        </div>
                        <div class="group">
                              <input name="tbPassword" type="password" id="tbPassword"><span class="highlight"></span><span class="bar"></span>
                            <label>Password</label>
                        </div>

                           <input type="submit" name="btnLogIn" value="Login" onclick="return validation();" id="btnLogIn" class="button buttonBlue used">
                    </div>

any help?


回答1:


okay, so the reason i was getting an AttributeError because in simple language.. things are not being parsed from the object itself i.e. opens ,it is predefined that robobrowser is an automated browser, so every thing is being automated ,to whatever request or method or whatever code we write so we have to do,

print(browser.parsed)

instead of

print(opens.parsed)

thanks!



来源:https://stackoverflow.com/questions/42950610/how-to-remove-attributeerror-in-robobrowser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!