파이썬

웹 스크래핑 - 1

tpghks9245 2021. 3. 5. 14:45

# 웹 스크래핑(필요한 부분만)

웹 페이지에서 내가 원하는 부분만 떼오는 것

 

# 웹 크롤링(허용 범위를 알려줌)

웹 페이지에 있는 링크들을 따라가며 모든 정보 가져옴

 

웹 - html(집의 뼈대), css(인테리어), js(창문 전등 티비 등)로 구성

 

#주의할 점

웹은 항상 변동(구조가 변동)될 수 있기 때문에 이해 해야함.

 

HTML(Hyper Text Mark Language)

 

xpath

 

크롬 개발자 도구 사용법

 

requests

 

#1

 

# 정규식을 쓸때

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

# 2. m = p.match("비교할 문자열") : 주어진 문자열의 처음부터 일치하는지 확인

# 3. m = p.search("비교할 문자열") : 주어진 문자열 중에 일치하는게 있는지 확인

# 4. lst = p.findall("비교할 문자열") : 일치하는 모든 것을 "리스트" 형태로 반환

 

# 원하는 형태 : 정규식

# . (ca.e) : 하나의 문자를 의미 > care, cafe, case (o) | caffe(x)

# ^ (^de) : 문자열의 시작 , desk, destination (o) | fade (x)

# $ (se$) : 문자열의 끝 , c ase, base (o) | face (x)

 

def print_match(m):

    if m:

        print("m.group():", m.group()) # 일치하는 문자열 반환

        print("m.string:", m.string) # 입력받은 문자열

        print("m.start():", m.start()) # 일치하는 문자열의 시작 index

        print("m.end():", m.end()) # 일치하는 문자열의 끝 index

        print("m.span():", m.span()) # 일치하는 문자열의 시작 / 끝 index

    else:

        print("매칭되지 않음")

 

# m = p.match("caseless") # 주어진 문자열의 처음부터 일치하는지 확인

# print_match(m)

 

# lst = p.findall("good care") # findall : 일치하는 모든 것을 리스트 형태로

# print(lst)

 

User Agent

www.whatismybrowser.com/detect/what-is-my-user-agent

 

What is my user agent?

Every request your web browser makes includes your User Agent; find out what your browser is sending and what this identifies your system as.

www.whatismybrowser.com

내 유저 정보를 알 수 있는 홈페이지(나 인증)