Exemplo n.º 1
0
    def test_cookies(self):
        # this test page depends on cookies, and an http-equiv refresh
        # cj = CreateBSDDBCookieJar("/home/john/db.db")
        cj = CookieJar()
        handlers = [
            HTTPCookieProcessor(cj),
            HTTPRefreshProcessor(max_time=None, honor_time=False),
            HTTPEquivProcessor(),

            HTTPRedirectHandler(),  # needed for Refresh handling in 2.4.0
            #            HTTPHandler(True),
            #            HTTPRedirectDebugProcessor(),
            #            HTTPResponseDebugProcessor(),
        ]

        opener = self.build_opener(handlers)
        r = opener.open(urljoin(self.uri, "/cgi-bin/cookietest.cgi"))
        data = r.read()
        self.assert_(data.find("Your browser supports cookies!") >= 0)
        self.assertEquals(len(cj), 2)

        # test response.seek() (added by HTTPEquivProcessor)
        r.seek(0)
        samedata = r.read()
        r.close()
        self.assertEquals(samedata, data)
    def test_cookies(self):
        import urllib2
        # this test page depends on cookies, and an http-equiv refresh
        #cj = CreateBSDDBCookieJar("/home/john/db.db")
        cj = CookieJar()
        handlers = [
            HTTPCookieProcessor(cj),
            HTTPRefreshProcessor(max_time=None, honor_time=False),
            HTTPEquivProcessor(),
            HTTPRedirectHandler(),  # needed for Refresh handling in 2.4.0
            #            HTTPHandler(True),
            #            HTTPRedirectDebugProcessor(),
            #            HTTPResponseDebugProcessor(),
        ]

        o = apply(build_opener, handlers)
        try:
            install_opener(o)
            try:
                r = urlopen(urljoin(self.uri, "/cgi-bin/cookietest.cgi"))
            except urllib2.URLError, e:
                #print e.read()
                raise
            data = r.read()
            #print data
            self.assert_(data.find("Your browser supports cookies!") >= 0)
            self.assert_(len(cj) == 1)

            # test response.seek() (added by HTTPEquivProcessor)
            r.seek(0)
            samedata = r.read()
            r.close()
            self.assert_(samedata == data)
Exemplo n.º 3
0
 def __init__(self):
     Browser.__init__(self)
     self.set_handle_redirect(True)
     self.set_handle_referer(True)
     self.set_handle_equiv(True)
     self.set_handle_robots(False)
     self.set_handle_referer(False)
     self.set_handle_refresh(HTTPRefererProcessor(), max_time=1)
     self.cookiejar = CookieJar()
     self.set_cookiejar(self.cookiejar)
Exemplo n.º 4
0
channel = raw_input("channel name")

"""Configuring the Browser using mechanize

[
    1) Instantiate browser class
    2) Configure it to not handle robot questions
    3) Intiantiate a CookieJar class
    4) Set the Browser's CookieJar to be the class just instantiated
]
"""
browser = Browser(history=None, request_class=None,
                  content_parser=None, allow_xhtml=False)
browser.set_handle_robots(False)
cookie = CookieJar(policy=None)
browser.set_cookiejar(cookie)
browser.addheaders = [
    ('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.7 (KHTML, like Gecko) Chrome/7.0.517.41 Safari/534.7')]
browser.set_handle_refresh(False)

"""Opening the website and browser

[
    1) Get reponse from inputting workspace url
    2) Get reponse from inputting email and password
]
"""

# workspace url
browser.open(url)
        print "Please Fill EMAIL,PASSWORD and HOST_URL on settings.py!"
        print "Exiting"
        exit()

    browser = Browser()

    debug_headers_flag = False
    try:
        debug_headers_flag = sys.argv[1] == '-d'
    except IndexError as e:
        None

    if debug_headers_flag:
        browser.set_debug_http(True)

    cookies = CookieJar()

    browser.set_handle_refresh(False)
    browser.set_handle_robots(False)
    browser.set_cookiejar(cookies)

    browser.addheaders = [(
        'User-agent',
        'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/68.0'
    )]

    browser.open(settings.HOST_URL)

    login(browser)

    for index, carta in enumerate(get_cartas_id(browser)):