hahahia

[Python] URL Regular Expression 본문

Language/Python

[Python] URL Regular Expression

hahahia 2012. 11. 10. 17:36


/* 정규식을 이용하여 html 소스에 있는 URL 주소들을 리스트(a) 로 반환하고 출력합니다 */

opener = urllib2.build_opener(

                urllib2.HTTPHandler(),

                urllib2.HTTPSHandler(),

                urllib2.ProxyHandler({'https': 'http://user:pass@proxy:3128'}))

urllib2.install_opener(opener)

html = urllib2.urlopen(SeedURL).read()

fw = open("URL_List.txt", 'w')

crawl = "(http|https):\/\/(([\xA1-\xFEa-z0-9_\-]+\.[\xA1-\xFEa-z0-9:;&#@=_~%\?\/\.\,\+\-]+))" 

a = re.findall(crawl, html)

for i in a :

    fw.write(i[1]+ "\n")

    recur(i[1])

fw.close()




Comments