IT/python
파이썬에서 특정 태그를 쓴 구문 찾기
나의지식
2021. 4. 4. 18:57
파이썬에서 xml이나 html 문서에서 특정 태그를 쓴 구문을 찾으려면 re를 import하고
a=re.findall(r'<totalCount>.+?</totalCount>', text)
와 같이 쓰면 된다. 여기서 text는 xml이나 html 파일이고 이렇게 입력할 경우 totalCount라는 태그를 쓴 명령어줄을 찾는다.
즉 <totalCount>252</totalCount>와 같이 특정 태그를 쓴 구문이 변수 a로 들어간다는 말이다.
반응형