Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- JavaScript
- extjs
- LINQ
- Config
- 스냅잘찍음
- 상속
- ORM
- Request
- lazy loading
- Store
- 명시적외래키
- EFCore
- intellij
- 대전본식영상
- JSON
- extraParams
- c#
- ViewModel
- mac
- 에스가든스냅
- .net
- vscode
- scanner
- React
- error
- 코드프로그래머스
- dbContext
- c#코딩의기술실전편
- minimalAPI
- 라도무스dvd
Archives
- Today
- Total
ejyoo's 개발 노트
BeautifulSoup 설치 본문
ejyoo.tistory.com/189?category=942603
<!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
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 |