예제 #1
0
 def login(self):
     """登录"""
     self.driver.find_element_by_id("id_username").clear()
     self.driver.find_element_by_id("id_pwd").clear()
     self.driver.find_element_by_id("id_username").send_keys(u"1281490")
     self.driver.find_element_by_id("id_pwd").send_keys(u"Zengyichao!123")
     self.driver.find_element_by_id("a_changeone").click()
     time.sleep(2)
     self.driver.save_screenshot("tuoful.png")  # 截取当前页面全图
     element = self.driver.find_element_by_id("imgVerifycode")  # 验证码的按钮
     # 计算出元素上、下、左、右 位置
     left = element.location["x"]
     top = element.location["y"]
     right = element.location["x"] + element.size["width"]
     bottom = element.location["y"] + element.size["height"]
     im = Image.open("tuoful.png")
     im = im.crop((int(left), int(top), int(right), int(bottom)))
     im.save("yz.png")
     # codeContent = raw_input("读取验证码内容:")#临时
     codeContent = YDMHttp().start()  # 云打码
     self.driver.find_element_by_name("LoginCode").send_keys(codeContent)
     self.driver.find_element_by_id("id_login").click()
     time.sleep(2)
     content = self.driver.page_source
     if "我的首页" in content:
         return True
     else:
         return False
 def jpg2str(self, num, content_pic):
     """
         功能:提交到打码平台,把验证码转换到string
         参数:图片链接
         返回:识别后的验证码       
     """
     file_name = "%s.jpg" % num
     f = open(file_name, 'wb')
     f.write(content_pic.content)
     f.close()
     codeContent = YDMHttp().start(file_name)  # 云打码
     os.system("rm -rf %s" % file_name)
     return codeContent
예제 #3
0
 def get_zuowei(self):
     """得到一个月的一个地区的考场信息"""
     scroll_add_crowd_button = self.driver.find_element_by_id("footer")
     self.driver.execute_script("arguments[0].scrollIntoView();",
                                scroll_add_crowd_button)
     time.sleep(3)
     self.driver.save_screenshot("tuoful.png")  # 截取当前页面全图
     im = Image.open("tuoful.png")
     im = im.crop((314.0, 377.0, 404.0, 412.0))
     im.save("yz.png")
     # codeContent2 = raw_input("读取验证码内容:")#临时
     codeContent2 = YDMHttp().start()
     self.driver.find_element_by_name("afCalcResult").send_keys(
         codeContent2)
     time.sleep(30)
     self.driver.find_element_by_name("submit").click()
     time.sleep(2)
     content = self.driver.page_source
     time1 = re.findall(r'<tr bgcolor="#FFCC99">(.*?)</tr>', content,
                        re.S)  # 匹配时间地区
     if time1 != []:
         time2 = time1[0]  # 匹配时间地区
         time_clear = re.findall(r'<b>(.*?)</b>', time2, re.S)
         are_str = time_clear[1]
         section_list = re.findall(
             r'(<tr.*?>.*?</tr>)',
             re.search(
                 r'<table cellpadding="4" cellspacing="1">(.*?)</table>',
                 content, re.S).group(), re.S)
         timedate = None
         for section in section_list[1:]:
             time_d = re.findall(r'<td.*?><b>(.*?)</b></td>', section, re.S)
             if time_d != []:
                 timedate = time_d[0]
             res_list = []
             aim_list = re.findall(r'<tr bgcolor="#CCCCCC">(.*?)</tr>',
                                   section, re.S)
             for aim in aim_list:
                 aim_clear = re.findall(r'<td.*?>(.*?)</td>', aim, re.S)
                 if "有名额" in aim_clear:
                     aim_clear[0] = timedate + are_str
                     res_list.append(aim_clear)
             with open("test.csv", "ab+") as csvfile:  # 保存到csv
                 writer = csv.writer(csvfile)
                 writer.writerows(res_list)
         return "no error"
     else:
         return content
예제 #4
0
 def get_zuowei(self):
     """得到一个月的一个地区的考场信息"""
     scroll_add_crowd_button = self.driver.find_element_by_id("footer")
     self.driver.execute_script("arguments[0].scrollIntoView();", scroll_add_crowd_button)
     time.sleep(3)
     self.driver.save_screenshot("tuoful.png")  # 截取当前页面全图
     # element = self.driver.find_element_by_xpath('//*[@id="maincontent"]/form/table[3]//tr[2]/td[2]/table//tr/td[1]/img')  # 验证码的按钮
     # 计算出元素上、下、左、右 位置
     # left = element.location["x"]
     # top = element.location["y"]
     # right = element.location["x"] + element.size["width"]
     # bottom = element.location["y"] + element.size["height"]
     im = Image.open("tuoful.png")
     #im = im.crop((left, top, right, bottom))
     im = im.crop((314.0, 377.0, 404.0, 412.0))
     im.save("yz.png")
     # codeContent2 = raw_input("读取验证码内容:")#临时
     codeContent2 = YDMHttp().start()
     self.driver.find_element_by_name("afCalcResult").send_keys(codeContent2)
     self.driver.find_element_by_name("submit").click()
     time.sleep(2)
     content = self.driver.page_source
     time1 = re.findall(r'<tr bgcolor="#FFCC99">(.*?)</tr>', content, re.S)[0]  # 匹配时间地区
     time_clear = re.findall(r'<b>(.*?)</b>', time1, re.S)
     time_str = time_clear[0] + time_clear[1]
     res_list = []
     aim_list = re.findall(r'<tr bgcolor="#CCCCCC">(.*?)</tr>', content, re.S)
     for aim in aim_list:
         aim_clear = re.findall(r'<td.*?>(.*?)</td>', aim, re.S)
         if "有名额" in aim_clear:
             aim_clear[0] = time_str
             res_list.append(aim_clear)
     with open("test.csv", "ab+") as csvfile:  # 保存到csv
         writer = csv.writer(csvfile)
         # 先写入columns_name
         writer.writerow(
             ["time----------", "id----------", "dizhi--------------------------------------", "money----------",
             "zhuangtai---------"])
         # 写入多行用writerows
         writer.writerows(res_list)