Python实现从URL列表中筛选含特定关键词的URL
解决方案
问题需求
爬取网页URL列表后,筛选出包含“decision-makers”的链接(注:当前示例输出中的链接拼写为decidion-makers,若为笔误可自行调整判断字符串)。
修改后的代码
src = driver.page_source # 使用BeautifulSoup解析 soup = BeautifulSoup(src, 'lxml') for a in soup.find_all('a', href=True): # 筛选包含目标字符串的URL if 'decision-makers' in a['href']: print(a['href'])
说明
在原遍历逻辑中增加判断条件,仅当链接href属性包含指定字符串时才输出,即可得到符合要求的结果。
期望输出
https://www.linkedin.com/jobs/?decidion-makers
内容的提问来源于stack exchange,提问作者Sushmitha
相关产品推荐
相关产品推荐

