面试题第十二关:
第一部分——考点:
- findall函数的使用
- Url的搜索
第二部分——面试题:
1.面试题一:提取HTML页面中所有的Url,要求:这些Url都属于a节点的Href属性。
第三部分——解析:
import re
s = '<a href="https://geekori.com">即刻起源</a> <a href="https:www.microsoft.com">微软</a>'
r = re.findall('<a href="(.*?)".*?a>', s, re.I)
print(r)
输出只有:
https://geekori.com
https:www.microsoft.com