python使用正则表达式提取网页URL的方法
时间:2021-09-20 09:08:45|栏目:Python代码|点击: 次
本文实例讲述了python使用正则表达式提取网页URL的方法。分享给大家供大家参考。具体实现方法如下:
import re
import urllib
url="https://www.jb51.net"
s=urllib.urlopen(url).read()
ss=s.replace(" ","")
urls=re.findall(r"<a.*?href=.*?<\/a>",ss,re.I)
for i in urls:
print i
else:
print 'this is over'
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript
正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg
希望本文所述对大家的Python程序设计有所帮助。
栏 目:Python代码
下一篇:Ubuntu18.04中Python2.7与Python3.6环境切换
本文地址:http://www.codeinn.net/misctech/176197.html






