반응형
일단은 뷰티플솝 설치
pip install requests beautifulsoap4
이미 설치 되어있네..
언제설치했지?
네이버 땡겨봄
from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://www.naver.com")
bsObject = BeautifulSoup(html, "html.parser")
#전체 출력 - 바로됨
print(bsObject)
# 원하는 요소 찾는 예제
for meta in bsObject.head.find_all('meta'):
print(meta.get('content'))
# 어트리뷰트로 찾는 예제 이건 뭔가 이상하게 나옴
print (bsObject.head.find("meta", {"name":"description"}))
잘됨
속성으로 검색해서 찾으면 배열이 이상하게 나오긴 하지만 되긴 됨.
나중에 파싱하는 부분 정리하면 될 것 같음
다른 거 해보자
a 태그 가져오기
from urllib.request import urlopen
from bs4 import BeautifulSoup
# http://www.naver.com
html = urlopen("https://search.shopping.naver.com/search/all?query=%EB%B3%B6%EC%9D%8C%EB%B0%A5&cat_id=&frm=NVSHATC")
bsObject = BeautifulSoup(html, "html.parser")
for atags in bsObject.body.find_all("a"):
print (atags.get('href'))
오~ 잘됨
반응형
'파이썬 공부' 카테고리의 다른 글
파이썬으로 php에 json 보내기 삽질하는 중 (0) | 2022.12.28 |
---|---|
파이썬공부 웹뷰 띄우기 (1) | 2022.11.24 |
조코딩 님의 파이썬 공부하기 좋은 영상 (0) | 2022.10.24 |
다시 공부하는 중 (0) | 2022.07.17 |
파이썬 배우기 - 웹페이지의 html을 그대로 가져오는거 해보는 중 (0) | 2021.11.09 |