diff --git a/lib/crawler.py b/lib/crawler.py index 6a80965..24b6f3e 100644 --- a/lib/crawler.py +++ b/lib/crawler.py @@ -53,8 +53,10 @@ class Crawler(object): r = self.__session.get( url='http://portal-cust-edu-cn-s.webvpn.cust.edu.cn:8118/custp/index') soup = BeautifulSoup(r.text, 'html.parser') - if soup.findAll(name='a')[-2]['href'] != 'logout': - return ('账号或者密码错误', 510) + try: + soup.findAll(name='a')[-2]['href'] + except Exception as e: + return ('账号或者密码错误', 510) r = self.__session.get( url='http://mysso-cust-edu-cn-s.webvpn.cust.edu.cn:8118/cas/login?service=http://jwgls1.cust.edu.cn:8080/welcome', allow_redirects=False) ticket = r.headers['Location'][72:] @@ -87,7 +89,6 @@ class Crawler(object): headers=headers ) data = json.loads(r.content.decode('utf-8')) - print(data) if data['state'] != 0: return ('教务挂了', 512) # 分解数据并重命名 diff --git a/lib/crawler_test.py b/lib/crawler_test.py index 3cbc6eb..428b718 100644 --- a/lib/crawler_test.py +++ b/lib/crawler_test.py @@ -19,7 +19,6 @@ class TestCrawler(unittest.TestCase): # 测试返回信息 def test_getData(self): get_res = c.getData() - print(get_res) self.assertEqual(get_res[-1], 200) if __name__ == '__main__':