반응형
- 파이썬 설치
Linux :
sudo apt-get update
sudo apt-get install python3
- requests 라이브러리 설치
pip install requests
- Beautiful Soup 라이브러리 설치
pip install beautifulsoup4
- 웹 크롤링 예제 코드 작성
import requests
from bs4 import BeautifulSoup
url = 'https://news.naver.com'
response = requests.get(url)
# HTML 파싱
soup = BeautifulSoup(response.text, 'html.parser')
# 뉴스 제목 추출
news_titles = soup.select('.cjs_t')
print('start')
# 결과 출력
for title in news_titles:
print(title.text)
- 실행
$ python3 test.py
반응형
'IT & 개발 > etc' 카테고리의 다른 글
VSCode에서 Flask 애플리케이션 디버깅: 포트 설정 가이드 (0) | 2025.01.08 |
---|---|
생성형 AI 챗GPT 활용법: 코드 작성 및 디버깅 (3) | 2024.10.07 |
[AWS-EC2] ufw 활성화 후 connection time out 문제 (0) | 2023.07.20 |
[GIT] vscode git auto login(git credential) 설정 (0) | 2023.06.19 |
[AI 자동투자 봇] 키움증권 KOA 스튜디오 api 접속 오류 (0) | 2022.09.26 |