本文實(shí)例講述了python使用正則表達(dá)式提取網(wǎng)頁URL的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:
1
2
3
4
5
6
7
8
9
10
|
import re import urllib url = "http://m.ythuaji.com.cn" 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' |
希望本文所述對大家的Python程序設(shè)計(jì)有所幫助。