-
Notifications
You must be signed in to change notification settings - Fork 0
/
responsehandler.py
51 lines (36 loc) · 1.07 KB
/
responsehandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
# coding: utf-8
from bs4 import BeautifulSoup
import re
def failure(html):
return html.find_all("div", {"class":"pl_noresult"})
def success(html):
return html.find_all("div", {"class":"feed_lists search_notes"})
# Term cannot be displayed
def blocked(html):
return failure(html, fail_message)
def no_results(w):
return re.match(u'\u62b1\u6b49\uff0c\u672a\u627e\u5230\u201c', w)
def few_results(html):
all_res = success_msg(html)
return len(all_res) < 5
def many_results(html):
all_res = success_msg(html)
return len(all_res) >= 5
class ResponseHandler():
def __init__(self, html):
self.soup = BeautifulSoup(html, "html.parser")
def response_type(self):
res = failure(self.soup)
if res:
if no_results(res[0].find_all("p", {"class":"noresult_tit"})[0].get_text(' ', strip=True)):
return "NO_RESULTS"
else:
return "BLOCKED"
elif success(self.soup):
if success(self.soup) < 5:
return "FEW_RESULTS"
else:
return "MANY_RESULTS"
else:
return "ERROR CHECKING RESULTS"