Total Complexity | 5 |
Total Lines | 31 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | # -*- coding: utf-8 -*- |
||
2 | from __future__ import absolute_import, unicode_literals |
||
3 | |||
4 | import re |
||
5 | |||
6 | from bs4 import BeautifulSoup |
||
7 | |||
8 | from school_api.exceptions import OtherException |
||
9 | |||
10 | |||
11 | def get_alert_tip(html): |
||
12 | ''' 获取页面提示信息 ''' |
||
13 | tips = re.findall(r">alert\(\'(.*?)\'", html) |
||
14 | if tips: |
||
15 | return tips[0] |
||
16 | return None |
||
17 | |||
18 | |||
19 | def get_view_state_from_html(html): |
||
20 | ''' 获取 __VIEWSTATE 值 ''' |
||
21 | pre_soup = BeautifulSoup(html, "html.parser") |
||
22 | view_state_soup = pre_soup.find(attrs={"name": "__VIEWSTATE"}) |
||
23 | try: |
||
24 | view_state = view_state_soup['value'] |
||
25 | except TypeError: |
||
26 | if html.find("网站防火墙") > -1: |
||
27 | raise OtherException('', "请求被防火墙所拦截, 请降低请求频率") |
||
28 | raise OtherException('', '获取view_state失败') |
||
29 | |||
30 | return view_state |
||
31 |