本文實例講述了python獲取指定網頁上所有超鏈接的方法。分享給大家供大家參考。具體如下:
這段python代碼通過urllib2抓取網頁,然后通過簡單的正則表達式分析網頁上的全部url地址
import urllib2import re#connect to a URLwebsite = urllib2.urlopen(url)#read html codehtml = website.read()#use re.findall to get all the linkslinks = re.findall('"((http|ftp)s?://.*?)"', html)print links希望本文所述對大家的python程序設計有所幫助。
新聞熱點
疑難解答