驱动控制浏览器 和排程算法
#从selenium框架中导入浏览器驱动 """ 我们就是使用浏览器驱动去控制我们浏览器 """ from selenium import webdriver#自动化测试框架 , 去对接scrapy框架去做爬虫 #WebDriverWait:是让浏览器等待加载 from selenium.webdriver.support.ui import WebDriverWait import time import log.settings class taobao_infos: #对象初始化 def __init__(self): #让浏览器指定的页面 淘宝登录页 url="https://login.taobao.com/member/login.jhtml?" self.url=url self.brower=webdriver.Chrome(executable_path="G:\\PY\\chromedriver_win32\\chromedriver.exe") # self.brower=webdriver.phantomjs #无界面浏览器 self.wait=WebDriverWait(self.brower,10) #登录淘宝 def login(self): #打开淘宝登录页 self.brower.get(self.url) if self.brower.find_element_by_link_text("密码登录"): self.brower.find_element_by_link_text("密码登录").click() #等待微博登录选项出现 if self.brower.find_element_by_xpath('//*[@id="J_OtherLogin"]/a[1]'): self.brower.find_element_by_xpath('//*[@id="J_OtherLogin"]/a[1]').click() time.sleep(1) #等待微博账号出现 if self.brower.find_element_by_xpath('//*[@id="pl_login_logged"]/div/div[2]/div/input'): weibo_user=self.brower.find_element_by_xpath('//*[@id="pl_login_logged"]/div/div[2]/div/input') #send_keys是针对输入框自动填入你想要的值 weibo_user.send_keys(weibo_username) #微博密码 if self.brower.find_element_by_xpath('//*[@id="pl_login_logged"]/div/div[3]/div/span'): weibo_pwd=self.brower.find_element_by_xpath('//*[@id="pl_login_logged"]/div/div[3]/div/input') weibo_pwd.send_keys(weibo_password) #点击登录 if self.brower.find_ele4ment_by_link_text("登录"): submit=self.brower.find_element_by_link_text("登录") submit.click() if __name__=="__main__": weibo_username=log.settings.username weibo_password=log.settings.password #登录 a=taobao_infos() a.login()
排程
Python代码
def main(list1,list2,num): rows=zip(list1,list2) num=int(num) rows=list(rows) rows.sort(key=lambda x:x[1]) rows.reverse() total=[] lists = [[] for i in range(num)] for m in range(0,num): total.append(8) for row in rows: print(row) min_time = total[0] k = 0 for j in range(1,num): if min_time > total[j]: k = j min_time = total[j] total[k]+=int(row[1]) lists[k].append(row[0]) return lists
C#代码
List<string> l1 = new List<string> { "k2", "k1", "k3","k4","k5" }; List<double> l2 = new List<double> { 3,5,2,1,0.5}; int num = 2;//2间手术室 double temp = 0; string temps = ""; for (int i = 0; i < l2.Count-1 ; i++) { for (int j = i+1; j < l2.Count; j++) { if(l2[i]<l2[j]) { temp = l2[i]; l2[i] = l2[j]; l2[j] = temp; temps = l1[i]; l1[i] = l1[j]; l1[j] = temps; } } } string[,] bString = new string[num, l1.Count()]; int max = l1.Count() * num; int te = 0; int count = 0; int x = 0; for (int i = 0; i < max; i++) { bString[x, te] = l1[count]; count += 1; x += 1; if (count>= l1.Count) { break; } if (x == num) { x = 0; te += 1; } } for (int i = 0; i < num; i++) { for (int j = 0; j < l1.Count; j++) { if (bString[i, j] != null) { string id = bString[i, j]; } } }