Development/Python
2BPerfect...12
Kirok Kim
2022. 1. 27. 11:39
์น ์คํฌ๋ํ
#pandas ๋ด๋ถ์ ์ผ๋ก matplotlib์ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์
# ๊ฐ๋จํ ๊ทธ๋ํ๋ผ๋ฉด pandas๋ง import ์์ผ๋ ๋จ!
# ์น์ฌ์ดํธ
## ํ๋
import webbrowser
url=naver~
webbrowser.open(url)
naver_search_url='~/search.naver?query='
search_word='ํ์ด์ฌ'
url=nsu+sw
webbrowser.open_new(url)
##์ฌ๋ฌ๊ฐ
urls=['๋ค์ด๋ฒ','๊ตฌ๊ธ'~]
for url in urls:
webbrowser.open_new(url)
search_words=['ํ์ด์ฌ','','']
for search_word in sws:
webbrowser.open_new(url+search_word)
# ์นํ์ด์ง ์์ค ๊ฐ์ ธ์ค๊ธฐ
import requests
r=requests.get('')
r
r.text[0:100] ์ด๊ฒ์ผ๋ก ๊ฐ์ ธ์จhtml ์์ค๋ฅผ ํ์ธ
html=r=requests.get('').text
## ์์ค๋ฅผ ์ข ๋ ๋ณด๊ธฐ ์ฝ๊ฒ ํ๋ ๊ฒ Parser Beautifulsoup
# html ๋ถ์ ํ์ฑ(parsing) ์ํ๋ ํ๊ทธ๋ฅผ ๊ฒ์ ์ถ์ถ
print(soup.prettify() ) # ์ธํฐ๋ท์์ ๋ณด๋ ํธ๋ฆฌํ์์ผ๋ก ์ถ๋ ฅ
from bs4 import BeautifulSoup
bs=BeautifulSoup(req.text,'html.parser')
bs.find('').get_text() #''ํ๊ทธ text ์ถ์ถ
#bs.find('ํ๊ทธ','์์ฑ')=๋จ์ ํ๊ทธ๋ง ๊ฒ์, ๋ณต์กํ ๊ตฌ์กฐ ๊ฒ์ ๋ถ๊ฐ๋ฅ
#bs.find_all('ํ๊ทธ','์์ฑ')= ๋จ์ ํ๊ทธ๋ง ๊ฒ์ ๋ณต์กํ ๊ตฌ์กฐ ๊ฒ์ ๋ถ๊ฐ๋ฅ
sn=bs.find_all('')
for s in sn:
print(s.get_text())
bs.title
bs.body
bs.body.h1
bts=bs.find_all('p',{'id':'book_title'})
aus=bs.find_all('p',{'id':'author'})
for bt,au in zip(bts,aus):
print(bt.get_text()+'/'+au.get_text())
'''
์ฃผ์ css5๊ฐ์ง
#id id='id๊ฐ'
.class class='class๊ฐ' .cls1.cls2 ํด๋์ค๊ฐ์ฌ๋ฌ๊ฐ ๊ฐ์ง๊ณ ์๋ ์ ํ์ class='cls1 cls2'
tag <tag>
์ ํ์1> ์ ํ์2 ์์ ์ ํ์
์ ํ์1 ์ ํ์2 ์์ ์ ํ์
'''
bs.select('css์ ํ์') select๋ ๋ค์ค ์ ํ
bs.select_one('category') select_one ํ๋๋ง ์ ํ
bs.select('body p')
bs.select('p#book_title')
๋ฐ์ํ