web信息收集:获取所有url
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)
本文来自博客园,作者:OTAKU_nicole,转载请注明原文链接:https://www.cnblogs.com/nicole-zhang/p/14421665.html