ejyoo's 개발 노트

BeautifulSoup 설치 본문

BackEnd/Python

BeautifulSoup 설치

ejyoovV 2021. 5. 10. 10:42

ejyoo.tistory.com/189?category=942603

 

파이썬 설치 및 이클립스 설치 후 환경설정

아나콘다 설치 => 이것 설치할때 작성된 순서를 그대로 하면 PYQT Designer도 함께 설치됨. => PYQT Designer 사용하려면 아나콘다 설치 후 콘솔에서 designer를 실행하면 됨. 이클립스 설치 파이썬 설치 완

ejyoo.tistory.com

wikidocs.net/85739

 

위키독스

온라인 책을 제작 공유하는 플랫폼 서비스

wikidocs.net

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>crawling</title>
</head>
<body>
	<table border='1'>
		<tr>
			<td>main target</td>
			<td>hp</td>
		</tr>
		<tr>
			<td>ito</td>
			<td>010-2222-3333</td>
		</tr>
		<tr>
			<td>lee</td>
			<td>010-2222-9463</td>
		</tr>
	</table>
</body>
</html>
import requests
from bs4 import BeautifulSoup

url = 'http://localhost:8080/CRAWAL/crawhtm.html'

response = requests.get(url)

if response.status_code == 200:
    html = response.text
    soup = BeautifulSoup(html, 'html.parser')
    print(soup)

else : 
    print(response.status_code)

 

 

api 사용하기

developers.naver.com/docs/serviceapi/search/blog/blog.md#%EB%B8%94%EB%A1%9C%EA%B7%B8

 

블로그 - Search API

블로그 NAVER Developers - 검색 API 블로그 검색 개발가이드 검색 > 블로그 네이버 블로그 검색 결과를 출력해주는 REST API입니다. 비로그인 오픈 API이므로 GET으로 호출할 때 HTTP Header에 애플리케이션

developers.naver.com

import os
import sys
import urllib.request

from bs4 import BeautifulSoup

client_id = "발급받은ID"
client_secret = "발급받은 비밀번호"
encText = urllib.parse.quote("치킨")
url = "https://openapi.naver.com/v1/search/blog.xml?query=" + encText # xml 결과
request = urllib.request.Request(url)
request.add_header("X-Naver-Client-Id",client_id)
request.add_header("X-Naver-Client-Secret",client_secret)
response = urllib.request.urlopen(request)
rescode = response.getcode()
if(rescode==200):
    response_body = response.read()
    
    html = response_body.decode('utf-8') # enclipse : 암호화 거는것
    soup = BeautifulSoup(html, 'html.parser')
    
    items = soup.select("item")
    for i,item in enumerate(items):
        print(item.title.text)
        print(item.description.text) 
        print()
        print()
     
else:
    print("Error Code:" + rescode)

'BackEnd > Python' 카테고리의 다른 글

HeidiSQL 설치 및 DB 생성  (0) 2021.05.11
MySQL 설치  (0) 2021.05.11
python db 연결 위한 mysql 설치  (0) 2021.05.10
pyQt5. button 클릭 시 label text 변경  (0) 2021.05.07
파이썬 설치 및 이클립스 설치 후 환경설정  (0) 2021.04.30