this is a code snippet print('hello world!')
this is a sentence.
#!/usr/bin/env python
# coding=utf-8
from bs4 import BeautifulSoup
import unittest
from selenium import webdriver
import time
self.driver.get("https://www.douyu.com/directory/all")
class Douyu(unittest.TestCase):
# 初始化方法,必须是setUp
def setUp(self):
self.driver = webdriver.Chrome()
self.num = 0
self.count = 0
for tries in range(maxTryNum):
try:
time.sleep(2)
login_page = self.session.post(self.post_url, data=data, headers=headers)
time.sleep(2)
# print(login_page.text)
if "errorMsg" in login_page.text:
print("登录失败,错误的手机号码或密码!")
# 将登录失败的手机号添加到一个列表中,颜色变为红色
fail_phone = []
fail_phone.append(self.username)
ProcessData().fail_high_light(fail_phone)
break
if "</span>首页" in login_page.text:
print("欢迎您'%s',成功登陆CBS管理系统!"%self.username)
# 登录成功的手机号码添加到列表中,颜色变为黑色,考虑之前登录失败后来登录成功的情况
success_phone = []
success_phone.append(self.username)
ProcessData().success_high_light(success_phone)
company_name = self.freight_on_list()
# 获取完数据后退出后台
time.sleep(2)
self.quit_on_list(company_name)
# 只要有登录成功的手机号,最后才会去调用合并功能
return len(success_phone)
except Exception as e:
if tries < (maxTryNum-1):
print("出错了,重新尝试第%d次中,问题为:%s"%(tries+1,e))
continue
else:
print("重新尝试次数超过限制",e)
break
# print("登陆成功!")s