python3-正则表达式(re)之获取网页全部url

版权声明:本文为博主原创文章,转载请附上博文链接 https://blog.csdn.net/weixin_44065501/article/details/89346178

有时候,我们需要获取网站的全部url,用作于其他测试

以sogoWeChat为例:

import re
import urllib.request

response = urllib.request.urlopen("https://weixin.sogou.com/")
html = response.read()
tag = re.findall(r'<a href="([a-zA-z]+://[^\s]*)"', str(html))
print(tag)
13136383-c838246ff19c7625.png
返回结果

推荐一个正则表达式在线验证网站:http://tool.oschina.net/regex/#

13136383-162063ab31de6200.png
完美

猜你喜欢

转载自blog.csdn.net/weixin_44065501/article/details/89346178