是RE模块没有下载么,,一直提示下面这个错误,哭唧唧o(╥﹏╥)o
listUrls = soup.findALL('a', href=re.compile('^wiki'))
TypeError: 'NoneType' object is not callable
用的是 win10+python3.5+pycharm 求大神解答,,o(╥﹏╥)o
#!/usr/bin/env python # -*- coding:utf-8 -*- import io import sys from urllib import request from bs4 import BeautifulSoup import re sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf8') resp = request.urlopen("http://news.baidu.com/").read().decode("utf-8") soup =BeautifulSoup(resp,"html.parser") listUrls=soup.find_all("a",href=re.compile(".*\/\/news\.baidu.*")) for url in listUrls: print (url.get_text(),"<------------>"+url["href"])
这个是我的,你可以参考一下
RE是自带的,跟sys和io类似,直接import就可以用,是你的正则写错了
还有你的beautifulSoup如果是最新版,用
find_all替代findALL