mechanize python xe 2330

Solutions on MaxInterview for mechanize python xe 2330 by the best coders in the world

showing results for - "mechanize python xe 2330"
Roberto
24 Feb 2017
1def create_new_account(username, email, password):
2    '''It returns True/False.'''
3
4    browser = mechanize.Browser()
5    browser.set_handle_robots(False)
6    browser.addheaders = [
7        ('User-agent',
8         'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'),
9        ('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
10        ('Accept-Encoding', 'gzip,deflate,sdch'),
11        ('Accept-Language', 'en-US,en;q=0.8'),
12        ('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')
13    ]
14    browser.set_handle_gzip(True)
15    res = browser.open('https://github.com')
16    browser.select_form(nr=1)
17    browser['user[login]'] = username
18    browser['user[email]'] = email
19    browser['user[password]'] = password
20    s = browser.submit()
21
22    second_page = s.read()
23    landing_page_fp = '/tmp/landing-%s.html' % username
24    with open(landing_page_fp, 'w') as f:
25        f.write(second_page)
26
27    expected_string = 'taken your first step into a larger world, <strong>@%s' % username
28    second_page = second_page.decode('ascii', 'ignore')
29    if second_page.find(expected_string) >= 0:
30        print 'SUCCESS for user %s' % username
31        return True
32    else:
33        # something went wrong
34        error_fp = '/tmp/errorpage-%s.html' % username
35        with open(error_fp, 'w') as f:
36            f.write(second_page)
37        print 'Something went wrong. Error page dumped to "%s"' % error_fp
38        return False 
similar questions
queries leading to this page
mechanize python xe 2330