반응형
- 파이썬 설치
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
반응형
'개발 > etc' 카테고리의 다른 글
[apache2] SPA(Single Page Application) 새로고침 시 404 error (0) | 2023.07.24 |
---|---|
[AWS-EC2] ufw 활성화 후 connection time out 문제 (0) | 2023.07.20 |
[GIT] vscode git auto login 설정 (0) | 2023.06.19 |
[Apache] upload file size limit (0) | 2022.10.05 |
[AI 자동투자 봇] 키움증권 KOA 스튜디오 api 접속 오류 (0) | 2022.09.26 |