Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please Help - Auto-Login
#1
Good Day,

I'm working on Auto-LogIn for the flowing webpage.
I'm very new to the Python; and I have been following a YouTube tutorial.

I need help to review my code.


import re

from robobrowser import RoboBrowser

br = RoboBrowser()
br.open("https://m.onlinebrokerage.cibc.com/#/signOn/en/ie")
form = br.get_form()
form['ng-pristine ng-valid ng-touched'] = "****"
form['field ng-pristine ng-valid ng-valid-maxlength ng-touched'] = "****"

br.submit_form(form)

src = str(br.parsed())
start = '<span class="S27">'
end = '</span>'

result = re.search('%s(.*)%s' % (start, end), src).group(1)

print(result)
My errors:
Error:
The code that caused this warning is on line 7 of the file C:/Users/tots/Desktop/PYTHON/Chrome/2/1.py. To get rid of this warning, change code that looks like this: BeautifulSoup(YOUR_MARKUP}) to this: BeautifulSoup(YOUR_MARKUP, "html.parser") markup_type=markup_type)) Traceback (most recent call last): File "C:/Users/tots/Desktop/PYTHON/Chrome/2/1.py", line 8, in <module> form['ng-pristine ng-valid ng-touched'] = "*****" TypeError: 'NoneType' object does not support item assignment
what should I replace 'ng-pristine ng-valid ng-touched' with? This field has no ID
And I'm Not sure what's wrong with line 7

please help
Reply
#2
You are not getting the form,so it return None.
>>> form = None
>>> form['something'] = '****'
Error:
Traceback (most recent call last):   File "<string>", line 301, in runcode   File "<interactive input>", line 1, in <module> TypeError: 'NoneType' object does not support item assignment
The problem here is that log in use JavaScripts here with AngularJS.
RoboBrowser dos not evaluate JavaScript,so then have to reverse engineering what Angular dos to do the same.
Or simpler use Selenium/PhantomJS to do this.
Example it will try to log in:
from selenium import webdriver
from bs4 import BeautifulSoup
import time
 
# Activate Phantom and deactivate Chrome to not load browser
#browser = webdriver.PhantomJS()
browser = webdriver.Chrome()
web_url = 'https://m.onlinebrokerage.cibc.com/#/signOn/en/ie'
browser.get(web_url)
user_name = browser.find_element_by_xpath('//input[@ng-model="pageState.username.value"]')
user_name.send_keys("Foo")
password = browser.find_element_by_xpath('//input[@ng-model="pageState.password.value"]')
password.send_keys("Bar")
time.sleep(2)
submit = browser.find_element_by_css_selector('#submitButton')
submit.click()

''' 
# Give source code to BeautifulSoup
soup = BeautifulSoup(browser.page_source, 'lxml')
welcome = soup.select('//title')
print(welcome.text)
'''
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020