from urllib.request import urlopen from lxml.html import parse parsed = parse(urlopen("https://www.cnblogs.com/nicole-zhang/")) doc = parsed.getroot() # 获取全部含有"nicole-zhang"的url # 变量名 = [表达式 for 变量 in 列表 if 条件] links = [lnk.get('href') for lnk in doc.findall('.//a') if "nicole-zhang" in str(lnk.get('href'))] print(links)