扫码关注官方订阅号
from bs4 import BeautifulSoup html=''' baidu google android ios ''' soup = BeautifulSoup(html,'lxml') links=soup.findAll("a") print(links)
比如只想找到 href对链接中有mobile关键字的 链接, 有没有办法在findAll中就取出来?
认证0级讲师
可以用2种方法:
alls = soup.findAll("a", href=re.compile("mobile"))#支持正则 # alls = soup.select("a[href*=\"mobile\"]")#第二种用css selector虽然不符合题主意思,但是一起说了
update:成功截图:
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
可以用2种方法:
update:

成功截图: