- 论坛徽章:
- 14
|
本帖最后由 reb00t 于 2016-06-27 14:13 编辑
回复 1# yakczh_cu
- import re
- from bs4 import BeautifulSoup
- html='''
- <a class="vip_class fl font14" href="/site/baidu" target="_blank">baidu</a>
- <a href="/site/google/
- " target="_blank">google</a>
- <a href="/mobile/list/?" target="_blank">android</a>
- <a href="/mobile/list/?" target="_blank">ios</a>
- '''
- soup = BeautifulSoup(html,'lxml')
- alls=soup.findAll("a", href=re.compile('mobile'))
- print(alls)
- 结果
- [<a href="/mobile/list/?" target="_blank">android</a>, <a href="/mobile/list/?" target="_blank">ios</a>]
复制代码 |
|