详细解析请参考 http://blog.youkuaiyun.com/linzch3/article/details/62444947
我在这里就讲一些自己遇到的问题
1.bs4.FeatureNotFound: Couldn't find a tree builder with the features you requested: html.parse. Do you need to install a parser library?
一开始只是以为是有些相关的包没有安装,然后尝试了重装了bs4,还是不行,然后还是仔细检查了一下代码...发现错误!
soup = BeautifulSoup(html, 'html.parser')
这一行中,html.parser应该加上双引号,调用的参数形式不正确。还有不少地方也是相似的错误,在这里就不一一列举了。
2.TypeError: object of type 'NoneType' has no len()
检查代码发现没有地方有len()函数,各种百度相似的问题,发现没有什么类似情况出现。然后想了想可能也是代码哪里还有错误没有发现。然后在检查代码时看到
try: if(k==0): kw = {} else: kw={ 'start':k,'filter':' '} r = requests.get(url, params=kw, headers={ 'User-agent':'Mozilla/4.0'}) r.raise_for_status() r.encoding = r.apparent_encoding return r.text except: