간단한 파이썬 웹사이트 크롤링(스크래핑) 예제 코드

아래 코드는 engadget.com의 최신 기사 타이틀을 가져오는 간단한 파이썬 크롤링 코드입니다.


# engadget 스크래핑 

from bs4 import BeautifulSoup

from pprint import pprint

import requests


#웹 페이지를 열고 소스코드를 읽어오는 작업

html = requests.get("https://www.engadget.com/")

soup = BeautifulSoup(html.text, 'html.parser')

html.close()


# 제목 영역 추출

data=soup.findAll('span',"th-underline")

title_list = [ t.text for t in data]

title_list = [item.strip() for item in title_list if str(item)] # 줄바꿈 태그 삭제 

pprint(title_list)

Data

번호 제목 글쓴이 조회 날짜
42
  • Presta
  • 7,554
  • 0
  • 01-24
7,554 01-24
열람
  • Presta
  • 2,938
  • 0
  • 01-24
2,938 01-24
40
  • Presta
  • 3,690
  • 0
  • 01-24
3,690 01-24
39
  • Presta
  • 2,335
  • 0
  • 11-08
2,335 11-08
38
  • Presta
  • 2,163
  • 0
  • 11-08
2,163 11-08
37
  • Presta
  • 2,038
  • 0
  • 11-07
2,038 11-07
36
  • Presta
  • 1,429
  • 0
  • 11-07
1,429 11-07
35
  • Presta
  • 1,889
  • 0
  • 11-07
1,889 11-07
34
  • Presta
  • 1,158
  • 0
  • 11-04
1,158 11-04
33
  • Presta
  • 1,682
  • 0
  • 10-01
1,682 10-01
32
  • Presta
  • 4,338
  • 0
  • 09-30
4,338 09-30
31
  • Presta
  • 5,004
  • 0
  • 09-30
5,004 09-30
30
  • Presta
  • 2,769
  • 0
  • 09-29
2,769 09-29
29
  • Presta
  • 5,552
  • 0
  • 09-29
5,552 09-29
28
  • Presta
  • 1,530
  • 0
  • 09-22
1,530 09-22
페이팔 바로가기 EMS 국제배송 바로가기
이베이 바로가기 아마존 바로가기
접속자집계
  • 오늘 : 107
  • 어제 : 79
  • 최대 : 471
  • 전체 : 150,218