#导入开发包 from urllib.request import urlopen from bs4 import BeautifulSoup import re resp = urlopen("https://zh.wikipedia.org/wiki/Wikipedia:%E9%A6%96%E9%A1%B5").read().decode("utf-8") soup = BeautifulSoup(resp,"html.parser") listUrls = soup.findAll("a", href=re.compile("^/wiki/")) for url in listUrls: print(url("href"))
解决了,原来是用错括号了,把[ ]看成()了