Exemplo n.º 1
0
def log_in(idnum, password):
    headers = {
        "User-Agent":
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"
    }
    valcode = getpic(headers)
    f = open('valcode.png', 'wb')
    f.write(valcode.content)
    f.close()
    md5 = hashlib.md5(password.encode('utf-8')).hexdigest()
    print(idnum)
    print(password)
    code = datatest.main(cnn)
    data = {"id": idnum, "pwd": md5, "xdvfb": str(code)}
    resp = gethtml(checkUrl, headers,
                   requests.utils.dict_from_cookiejar(valcode.cookies), data)
    #resp = requests.post(checkUrl, headers = headers, cookies = requests.utils.dict_from_cookiejar(valcode.cookies), data=data)

    return resp
Exemplo n.º 2
0
def login():
    driver = webdriver.Firefox()
    driver.get('http://bkjw.whu.edu.cn/')
    i = 0
    while driver.current_url != 'http://bkjw.whu.edu.cn/stu/stu_index.jsp' and i < 10:
        global codeurl
        codeurl = get_preinf()
        valcode = getpic(headers)
        f = open('valcode.png', 'wb')
        f.write(valcode.content)
        f.close()
        driver.delete_cookie('JSESSIONID')
        cookies = driver.get_cookies()
        for cookie in cookies:
            print(cookie["name"], cookie["value"])
        cookies = requests.utils.dict_from_cookiejar(valcode.cookies)
        print(cookies)
        #driver.delete_all_cookies()
        print(type(cookies))
        driver.add_cookie({
            "name": "JSESSIONID",
            "value": cookies['JSESSIONID']
        })
        vcode = datatest.main(cnn)

        sleep(0.1)
        driver.find_element_by_name("id").send_keys(username)
        sleep(0.1)
        driver.find_element_by_name("pwd").send_keys(password)
        sleep(0.1)
        driver.find_element_by_name("xdvfb").send_keys(vcode)
        sleep(0.1)
        driver.find_element_by_id("loginBtn").click()
        sleep(0.1)
    if i < 10:
        return 1
    return 0
Exemplo n.º 3
0
        self.assertValid(data, requirement)

    def test_using_dict(self):
        """Check that values satisfy requirements of matching keys."""
        data = {
            'A': 100,
            'B': 200,
            'C': 299,
            'D': 405,
        }
        requirement = {
            'A': 100,
            'B': 200,
            'C': 300,
            'D': 400,
        }
        self.assertValid(data, requirement)

    def test_using_list(self):
        """Check that the order of values match the required sequence."""
        data = ['A', 'D', 'XXX', 'YYY', 'E', 'ZZZ', 'G']

        requirement = ['A', 'B', 'C', 'D', 'E', 'F', 'G']

        self.assertValid(data, requirement)


if __name__ == '__main__':
    datatest.main()