크롤링

크롤링

https://www.youtube.com/watch?v=yQ20jZwDjTE

# Requests

import requests res=requests.get("http://naver.com") res=requests.get("http://ccssbb.tistory.com") res.raise_for_status() # 이상하면 오류발생시키기 print(res.status_code) # if res.status_code == requests.codes.ok: # 상태코드가 200이면 # print("정상입니다") # else: # print("문제가 생겼습니다") print(len(res.text)) with open("mygoogle.html","w",encoding="utf8") as f: # mygoogle 파일 생성된다. f.write(res.text)

# re 정규식

- group() : 일치하는 문자열 반환

- string : 입력받은 문자열

- start() : 일치하는 문자열의 시작 index

- end() : 일치하는 문자열의 끝 index

- span() : 일치하는 문자열의 시작 / 끝 index

- findall() : 일치하는 모든 것을 리스트 형태로 반환

1. p = re.compile("원하는 형태")

2. m = p.match("비교할 문자열")

3. m = p.search("비교할 문자열")

4. lst = p.findall("비교할 문자열")

- 원하는 형태 : 정규식

from http://ccssbb.tistory.com/531 by ccl(A) rewrite - 2021-12-03 01:28:03