본문 바로가기
파이썬

파이썬 Regex to extract URLs from href attribute in HTML with Python

by º기록 2020. 9. 28.
반응형

가능한 중복 :


다음과 같은 문자열을 고려하십시오.


Python으로 앵커 태그의 href 내에서 URL을 어떻게 추출 할 수 있습니까? 다음과 같은 것 :

>>> url = getURLs(string)
>>> url
['http://example.com', 'http://example2.com']

감사!

 

해결 방법

 

import re


urls = re.findall('https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+', url) >>> print urls ['http://example.com', 'http://example2.com']

 

참조 페이지 https://stackoverflow.com/questions/6883049

 

 

반응형

댓글