def test_ddt_example_02(self, search_word, result_title): print("search_word-->", search_word) print("result_title-->", result_title) self.dr.get(self.base_url) baidu_search(self.dr, search_word) time.sleep(2) self.assertEquals(self.dr.title, result_title)
def run(): print() input('[*] 题目显示后,按回车搜索答案') img = public.screenshot() question = img.crop((130, 500, 950, 800)) answers = img.crop((130, 800, 950, 1600)) question = public.ocr(question) answers = public.ocr(answers, join=False) if question and answers: res = public.baidu_search(question) answer_index = best_answer(answers, res) if AUTO_CLICK: public.click(*ANSWER_POINTS[answer_index]) else: print('[*] 少年这题靠你自己了!')
from selenium import webdriver from time import sleep from public import baidu_search # 读取txt文件,建议使用'with open'方法 with open('./data/search_data.txt', 'r') as f: keywords_list = f.readlines() print(keywords_list) # 处理每一行末尾的回车符 keywords = [] for keyword in keywords_list: keywords.append(keyword.strip()) print(keywords) dr = webdriver.Chrome() for word in keywords: dr.get("https://www.baidu.com") baidu_search(dr, word) sleep(3) print(dr.title)
def test_ddt_example_04(self, search_word, result_title): # 函数的参数名必须与dict中的key相同 self.dr.get(self.base_url) baidu_search(self.dr, search_word) time.sleep(2) self.assertEquals(self.dr.title, result_title)
def test_ddt_example_03(self, search_word, result_title): self.dr.get(self.base_url) baidu_search(self.dr, search_word) time.sleep(2) self.assertEquals(self.dr.title, result_title)