인프런-이것이 진짜 크롤링이다 [기본편]을 보고 연습했고
환경설정은 python, VScode, beautifulsoup4 이다.
크롤링 연습 사이트
http://startcoding.pythonanywhere.com/basic
import requests
from bs4 import BeautifulSoup
response = requests.get("https://startcoding.pythonanywhere.com/basic")
html = response.text
soup = BeautifulSoup(html, 'html.parser')
soup.select_one("선택자")
선택자 글씨가 있는 위치에 태그 별명을 넣어주면 된다.
soup.select_one(".brand-name").text
'스타트코딩'
soup.select_one(".brand-name").attrs
{'class': ['brand-name'],
'href': 'https://www.youtube.com/channel/UCHwhZ7HPBhUh2IscPSL0pHA',
'target': '_blank'}
soup.select_one(".brand-name").attrs['href']
'https://www.youtube.com/channel/UCHwhZ7HPBhUh2IscPSL0pHA'
soup.select_one(".brand-name").attrs['target']
'_blank'
price = soup.select_one(".product-price").text.strip().replace(',','').replace('원','')
1419000
soup.select_one(".product-name > a").attrs['href']
#product1_detail.html