你的
get_page
函数没有返回html,它没有返回任何html。
def get_page(i=0, keyword="Political Science"):
...
html = response.read().decode('utf-8')
return # this is equivalent to return None (or not having this line at all)
应为:
def get_page(i=0, keyword="Political Science"):
...
return response.read().decode('utf-8')
因此出现错误:
In [11]: re.search("", None)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-1858f7517272> in <module>()
----> 1 re.search("", None)
/Users/andy/.miniconda3/lib/python3.6/re.py in search(pattern, string, flags)
180 """Scan through string looking for a match to the pattern, returning
181 a match object, or None if no match was found."""
--> 182 return _compile(pattern, flags).search(string)
183
184 def sub(pattern, repl, string, count=0, flags=0):
TypeError: expected string or bytes-like object