def own_pick(driver, sizeIdx, dts): print 'own_pick begins...' idx = 0 pIdx = 0 ele = dts[idx] move_to_ele(driver, ele) print platfm.local_str('可以开始控制了:通过1,2,3,4选取物品,通过j和k控制窗口移动') while True: c = platfm.read_terminal() if c == 'j': #向下 idx += 4 try: ele = dts[idx] #选取的内容越界了,函数返回 except: print platfm.local_str('进入下一页') return move_to_ele(driver, ele) elif c == 'k': #向上 if idx >= 4: idx -= 4 ele = dts[idx] move_to_ele(driver, ele, '') elif c == '1' or c == '2' or c == '3' or c == '4': no = idx + int(c) - 1 try: ele = dts[no] #选取的内容越界了,继续循环 except: continue href = ele.find_element_by_tag_name("a").get_attribute( 'href') + ' ' + sizeIdx + platfm.Line proc.send_to_subp(href) elif c == 'q': raise Exception #退出 print 'own_pick ends...'
def own_pick(driver,sizeIdx,dts): print 'own_pick begins...' idx=0 pIdx=0 ele=dts[idx] move_to_ele(driver,ele) print platfm.local_str('可以开始控制了:通过1,2,3,4选取物品,通过j和k控制窗口移动') while True: c=platfm.read_terminal() if c=='j': #向下 idx+=4 try: ele=dts[idx] #选取的内容越界了,函数返回 except: print platfm.local_str('进入下一页') return move_to_ele(driver,ele) elif c=='k': #向上 if idx>=4: idx-=4 ele=dts[idx] move_to_ele(driver,ele,'') elif c=='1' or c=='2' or c=='3' or c=='4': no=idx+int(c)-1 try: ele=dts[no] #选取的内容越界了,继续循环 except : continue href=ele.find_element_by_tag_name("a").get_attribute('href')+' '+sizeIdx+platfm.Line proc.send_to_subp(href) elif c=='q': raise Exception #退出 print 'own_pick ends...'
def auto_pick(driver, sizeIdx, dts): '''全自动模式''' print 'auto_pick begins...' for dl in driver.find_elements_by_class_name('J_pro_items'): try: title = dl.find_element_by_class_name('pro_list_tit').text print 'test', title if (not filter(lambda x: x in title, Excepts) and (Keywords and filter(lambda x: x in title, Keywords) == Keywords or not Keywords)): price = dl.find_element_by_tag_name("em").text.lstrip(u'¥') discount = dl.find_element_by_xpath( "./dd[@class='pro_list_data']/span").text discount = re.search(r'\((.*)\)', discount).group(1).rstrip(u'折') print 'price=', price, 'discount=', discount if (float(PriceSpan[0]) <= float(price) <= float(PriceSpan[1]) and float(DisSpan[0]) <= float(discount) <= float( DisSpan[1])): print 'pick it' href = ( dl.find_element_by_tag_name('a').get_attribute('href') + ' ' + sizeIdx + platfm.Line) proc.send_to_subp(href) # stop=raw_input('cont?') except Exception as e: #忽略可能出现的StaleElementReferenceException错误 print e print 'auto_pick ends...'
def auto_pick(driver,sizeIdx,dts): '''全自动模式''' print 'auto_pick begins...' for dl in driver.find_elements_by_class_name('J_pro_items'): try: title = dl.find_element_by_class_name('pro_list_tit').text print 'test',title if (not filter(lambda x:x in title,Excepts) and (Keywords and filter(lambda x:x in title,Keywords) == Keywords or not Keywords)): price = dl.find_element_by_tag_name("em").text.lstrip(u'¥') discount = dl.find_element_by_xpath("./dd[@class='pro_list_data']/span").text discount = re.search(r'\((.*)\)',discount).group(1).rstrip(u'折') print 'price=',price,'discount=',discount if (float(PriceSpan[0]) <= float(price) <= float(PriceSpan[1]) and float(DisSpan[0]) <= float(discount) <= float(DisSpan[1])): print 'pick it' href = (dl.find_element_by_tag_name('a').get_attribute('href') +' ' + sizeIdx+platfm.Line) proc.send_to_subp(href) # stop=raw_input('cont?') except Exception as e: #忽略可能出现的StaleElementReferenceException错误 print e print 'auto_pick ends...'