Posts
Q&A
์ด์ ๊ฐ์ ์ด์ด์ ์ง๋ฌธ๋๋ฆฝ๋๋ค
import requestsfrom bs4 import BeautifulSoupres = requests.get('https://v.daum.net/v/20170615203441266')soup = BeautifulSoup(res.content, 'html.parser')items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(1)')for item in items: print (item.get_text())items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(2)')for item in items: print (item.get_text()) items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(3)')for item in items: print (item.get_text()) items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(4)')for item in items: print (item.get_text()) ๋ค๋ค์ ๊ฐ์์ css selector๋ก ํด๋ณด๋ค๊ฐ ๋น์ทํ๊ฒ ๋ฐฉ๋ฒ์ ์ฐพ์์ด์ 1-4 ๊น์ง ๋ฐ๋ณต๋๋๊ฑธ ์ข ํธํ๊ฒ ๋ฐ๊พธ๊ณ ์ถ์๋ฐ ์์ง ๊ณต๋ถ๊ฐ ๋ถ์กฑํ์ง ์๊พธ ์ค๋ฅ๊ฐ ๋๋ค์ ใ ใ ์์ผ๋ก๋ ๋ชจ๋ฅด๋ ๋ด์ฉ์์ผ๋ฉด ๋ค์ ๊ฐ์๋ฅผ ์ข ๋ค์ด๋ณผ๊ฒ์ ใ ใ ๊ฐ์ฌํฉ๋๋ค
- 0
- 2
- 542
Q&A
ํจํด์ผ๋ก ์ค์ตํ๋ฉฐ ์ตํ๊ธฐ:html/css ์ดํด๋ฅผ ๋ฐํ์ผ๋ก ํฌ๋กค๋งํ๊ธฐ
import requestsfrom bs4 import BeautifulSoupres = requests.get('https://v.daum.net/v/20170615203441266')soup = BeautifulSoup(res.content, 'html.parser')items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(1)')for item in items: print (item.get_text())items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(2)')for item in items: print (item.get_text()) items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(3)')for item in items: print (item.get_text()) items = soup.select('div.news_view.fs_type1 > div.article_view > section > p:nth-child(4)')for item in items: print (item.get_text()) ๋ค๋ค์ ๊ฐ์์ css selector๋ก ํด๋ณด๋ค๊ฐ๊ฐ ๋น์ทํ๊ฒ ๋ฐฉ๋ฒ์ ์ฐพ์์ด์ 1-4 ๊น์ง ๋ฐ๋ณต๋๋๊ฑธ ์ข ํธํ๊ฒ ๋ฐ๊พธ๊ณ ์ถ์๋ฐ ์์ง ๊ณต๋ถ๊ฐ ๋ถ์กฑํ์ง ์๊พธ ์ค๋ฅ๊ฐ ๋๋ค์ ใ ใ ์์ผ๋ก๋ ๋ชจ๋ฅด๋ ๋ด์ฉ์์ผ๋ฉด ๋ค์ ๊ฐ์๋ฅผ ์ข ๋ค์ด๋ณผ๊ฒ์ ใ ใ ๊ฐ์ฌํฉ๋๋ค
- 0
- 2
- 559